#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "button.h"
#include "label.h"
#include "file.h"
#include "xml.h"
#include <stdio.h>
#include <QVBoxLayout>
#include <QPushButton>
#include <QFileDialog>
#include <QSettings>
#include <QPalette>
#include <QLineEdit>
#include <QTextEdit>
#include <QScrollBar>
#include <QMouseEvent>
#include <QCursor>
#include <QComboBox>
#include <QFrame>
#include <QCheckBox>
#include <QRadioButton>
#include <QValidator>
#include <QPlainTextEdit>
#include <QtXml/QDomDocument>
#include <QtXml/QDomProcessingInstruction>
#include <QtXml/QDomNotation>
#include <QtXml/QDomElement>
#include <QtXml/QDomNode>
#include <QIODevice>
#include <QDebug>
#include <QTimer>
#include <QDateTime>
#include <QDesktopServices>
#include <QUrl>
#include <QTimer>
#include <QTextStream>
#include <QTextCodec>
#include<QErrorMessage>
#include "/usr/include/python2.7/Python.h"

#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include<customerrordialog.h>
#define VALUE_DIS 5

//python执行后响应槽
void MainWindow::slot_Msg_py_end(int thread_type)
{
    qDebug() << "slot_Msg_py_end :" << thread_type;
    switch (thread_type) {
    case 1:
    {
        if(bFlag_type == 1) //打包
        {
            //打包
            //拼接新的包路径和名称
            QString dist_name = ui->lineEdit_target->text() +"/"+control_xml_1->sname_en->text()+"_"+control_xml_1->l_1->text()+"."+control_xml_1->l_2->text()+"."+control_xml_1->l_3->text() +"_"+ control_xml_1->larch->text()+".cpk";
            QString Command = QString("cpkg --pack %1  %2").arg(str_Source).arg(dist_name);
            thread_package2 = new Thread(Command);
            thread_package2->cache_dir = cache_dir;
            connect(thread_package2, SIGNAL(signal_Msg_pack_end(QString)),
                    this, SLOT(slot_Msg_pack_end(QString)));
            connect(thread_package2, SIGNAL(signal_Msg_error(QString)), this, SLOT(slot_Msg_pack_end(QString)));
            thread_package2->start();
            break;
        }
        else if(bFlag_type == 2) //转包
        {
            //转包的打包
            control_xml_2->create_xml(cache_dir);
            //重置安装脚本文件
//            set_script_into_file();
            //打包
            if( set_script_into_file() == 0 && !ui->lineEdit_target_2->text().isEmpty())
            {
                timer2 = new QTimer(this);
                connect(timer2,SIGNAL(timeout()),this,SLOT(timeUpDate2()));
                timer2->start(200);
                ui->progressBar_2->setFormat("正在打包中...");
                QStringList name = soft_name.split("_");
                //拼接新的包路径和名称
                QString dist_name = ui->lineEdit_target_2->text() +"/"+control_xml_2->sname_en->text()+"_"+control_xml_2->l_1->text()+"."+control_xml_2->l_2->text()+"."+control_xml_2->l_3->text() +"_"+ control_xml_2->larch->text()+".cpk";
                QString Command = QString("cpkg --pack %1  %2").arg(cache_dir).arg(dist_name);
                thread_package = new Thread(Command);
                thread_package->cache_dir = cache_dir;
                connect(thread_package, SIGNAL(signal_Msg_pack_end(QString)),
                        this, SLOT(slot_Msg_pack_end(QString)));
                connect(thread_package, SIGNAL(signal_Msg_error(QString)), this, SLOT(slot_Msg_pack_end(QString)));
                thread_package->start();
            }
        }

    }
    case 2:
    {
        break;
    }
    case 3:
    {
        break;
    }
    case 4:
    {
        break;
    }
    default:
        break;
    }
}

//显示true，隐藏false，进度条
void MainWindow::progreddBarEnable(bool y_n)
{
    if(ui->progressBar != NULL)
    {
        ui->progressBar->setVisible(y_n);
    }
    if(ui->progressBar_2 != NULL)
    {
        ui->progressBar_2->setVisible(y_n);
    }
    if(ui->progressBar_3 != NULL)
    {
        ui->progressBar_3->setVisible(y_n);
    }

}

//自定义错误对话框
//错误信息槽，弹出错误对话框
void MainWindow::slot_Msg_error(QString str_Msg_error)
{
    this->progreddBarEnable(false);

    CustomErrorDialog errorDialog(this);
    errorDialog.setWindowTitle("错误信息框");
    if(str_Msg_error != NULL)
    {
        errorDialog.setErrorInfo(str_Msg_error);
    }
    else
    {
        errorDialog.setErrorInfo("无错误信息！");
    }

    errorDialog.exec();
}

//使用系统错误对话框
////错误信息槽，弹出错误对话框
//void MainWindow::slot_Msg_error(QString str_Msg_error)
//{
//    this->progreddBarEnable(false);

//    QErrorMessage errorBox(this);
//    errorBox.setWindowTitle("错误信息框");
//    if(str_Msg_error != NULL)
//    {
//        errorBox.showMessage(str_Msg_error);
//    }
//    else
//    {
//        errorBox.showMessage("无错误信息！");
//    }

//    errorBox.exec();
//}

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setWindowTitle("应用转打包工具");
    this->setWindowIcon(QIcon("/usr/share/cpktransform/images/c_logo_64.png"));
    runPath = QCoreApplication::applicationDirPath();
    python_init();
    createUI_title();
    createUI_page_front();
    createUI_page1();
    createUI_page2();
    createUI_page3();
    createUI_page4();
    createUI_page5();
    createUI_page_error();

    m_bLeftButtonPress = false;
    ui->widget_b->setAutoFillBackground(true);//这个属性一定要设置

    QPixmap pixmap("/usr/share/cpktransform/images/background_2_bottom.png");

    //调色板
    QPalette   palette0;
    palette0.setBrush(ui->widget_b->backgroundRole(),QBrush(pixmap));

    //小部件
    ui->widget_b->setPalette(palette0);
    ui->widget_b->setFixedWidth(pixmap.width());
    ui->widget_b->setFixedHeight(pixmap.height());

    //进度条
    ui->progressBar->setFixedHeight(15);
    ui->progressBar->setFixedWidth(713);
    ui->progressBar_2->setFixedHeight(15);
    ui->progressBar_2->setFixedWidth(713);
    ui->progressBar_3->setFixedHeight(15);
    ui->progressBar_3->setFixedWidth(713);
    ui->progressBar->setValue(0);
    ui->progressBar->setFormat("");
    ui->progressBar_2->setValue(0);
    ui->progressBar_2->setFormat("");
    ui->progressBar_3->setValue(0);
    ui->progressBar_3->setFormat("");

    //超时?
    timer = new QTimer(this);
    connect(timer,SIGNAL(timeout()),this,SLOT(timeUpDate()));

    count = 0;
    count2 = 0;
    count3 = 0;

    ui->progressBar->setVisible(true);
    ui->progressBar_2->setVisible(true);
    ui->progressBar_3->setVisible(true);

    //1表示打包,2表示转包
    bFlag_type = 0;

    //change
    //    Qt::WindowFlags flags = 0;
    //    flags |= Qt::WindowMinimizeButtonHint;
    //    setWindowFlags(flags);   //禁止最大化

    //    setFixedSize(720,615);    //设置固定尺寸（禁止改变窗口大小）
    //    this->setMaximumSize(720,615);
    //    this->setMinimumSize(720,615);


    //    int width = this->geometry().width();
    //    int height = this->geometry().height();
    //    setFixedSize(width,height);

    connect(this,SIGNAL(signal_Msg_error(QString)), this, SLOT(slot_Msg_error(QString)));
}

MainWindow::~MainWindow()
{
    delete ui;  //early?
    if(dig1)      //need Yes
    {
        delete dig1;
        dig1 = NULL;
    }
    if(dig1)
    {
        delete dig1;
        dig1 = NULL;
    }
    if(dig2)
    {
        delete dig2;
        dig2 = NULL;
    }
    if(dig3)
    {
        delete dig3;
        dig3 = NULL;
    }
    if(dig4)
    {
        delete dig4;
        dig4 = NULL;
    }
    if(dig5)
    {
        delete dig5;
        dig5 = NULL;
    }
    if(dig6)
    {
        delete dig6;
        dig6 = NULL;
    }
    Py_Finalize();
}

void MainWindow::python_init()
{
    //初始化Python
    //在使用Python系统前，必须使用Py_Initialize对其
    //进行初始化。它会载入Python的内建模块并添加系统路
    //径到模块搜索路径中。这个函数没有返回值，检查系统
    //是否初始化成功需要使用Py_IsInitialized
    Py_Initialize();
    if(!Py_IsInitialized())
    {
        printf("Python初始化失败！");
    }
    //设置一下py文件所在目录
    PyRun_SimpleString("import sys");
    QString content = QString("sys.path.append('/usr/share/cpktransform/py')");
    PyRun_SimpleString(content.toLocal8Bit().data());
}

void MainWindow::createUI_title()
{
    //?
    centerWindow = new QWidget;

    //想要实现mouseTracking，若是setMouseTrack(true)，直接可以得到监听事件。
    //若是setMouseTrack(false),只有鼠标按下才会有mouseMove监听事件响应。
    this->setMouseTracking(true);

    this->setCentralWidget(centerWindow);
    ui->verticalLayout = new QVBoxLayout();
    ui->stackedWidget->setCurrentIndex(0);

    //标题栏
    t = new Titlebar();
    t->setAutoFillBackground(true);

    //标题栏透明色，使用透明图片
    QPixmap p_title1;
    p_title1.load("/usr/share/cpktransform/images/title_1.png");
    QPalette   palette_title1;
    palette_title1.setBrush(t->backgroundRole(),QBrush(p_title1));
    t->setPalette(palette_title1);

    t->setFixedWidth(p_title1.width());
    t->setFixedHeight(p_title1.height());

    //拖拽标题移动窗口
    connect(t, SIGNAL(signal_push_move_event(QPoint,QPoint)), this, SLOT(slot_get_move_event(QPoint,QPoint)));

    //帮助按钮
    QPixmap p_help;
    p_help.load("/usr/share/cpktransform/images/help.png");
    QToolButton* help = new QToolButton();
    help->setStyleSheet("QToolButton{border:1px groove gray;border-radius:5px; font-family:'Microsoft YaHei'; font-size:16px;border-style: flat;};");
    help->setFixedSize(16,16);
    help->setIcon(p_help);
    help->setIconSize(QSize(16,16));
    help->setToolTip("帮助");
    connect(help, SIGNAL(clicked()), this, SLOT(click_helpbutton()));

    //最小化按钮
    QPixmap p_minimize;
    p_minimize.load("/usr/share/cpktransform/images/minimize_normal.png");
    QToolButton* minimize = new QToolButton();
    minimize->setStyleSheet("QToolButton{border:1px groove gray;border-radius:5px; font-family:'Microsoft YaHei'; font-size:16px;border-style: flat;};");
    minimize->setFixedSize(p_minimize.width(),p_minimize.height());
    minimize->setIcon(p_minimize);
    minimize->setIconSize(QSize(p_minimize.width(),p_minimize.height()));
    minimize->setToolTip("最小化");
    connect(minimize, SIGNAL(clicked()), this, SLOT(click_minimizebutton()));

    //关闭按钮
    QPixmap p_close;
    p_close.load("/usr/share/cpktransform/images/close_normal.png");
    QToolButton* close = new QToolButton();
    close->setStyleSheet("QToolButton{border:1px groove gray;border-radius:5px; font-family:'Microsoft YaHei'; font-size:16px;border-style: flat;};");
    close->setFixedSize(p_close.width(),p_close.height());
    close->setIcon(p_close);
    close->setIconSize(QSize(p_close.width(),p_close.height()));
    close->setToolTip("关闭");
    connect(close, SIGNAL(clicked()), this, SLOT(click_closebutton()));

    //占位Label
    QLabel* occupying2 =new  QLabel();
    occupying2->setFixedWidth(5);


    QString logo_text = QString("\
                                <table width=\"100%\">\
                                <tbody>\
                                <tr>\
                                <td valign=\"middle\"><img src=\"/usr/share/cpktransform/images/c_logo_15.png\" ></td>\
                                <td>应用转打包工具</td>\
                                </tr>\
                                </tbody>\
                                </table>");

            //Logo标签   QLabel* label_logo;
    label_logo = new backLab();
    label_logo->setText(logo_text);
    //-5是为了能过显示文字底部的字体
    label_logo->setFixedHeight(p_title1.height() - 5);
//    设置光标样式
    label_logo->setCursor(Qt::PointingHandCursor);
    connect(label_logo, SIGNAL(Clicked(backLab*)), this, SLOT(click_btn_transbutton()));

    //QHBoxLayout水平布局
    horizontalLayout_header = new QHBoxLayout();
    horizontalLayout_header->addWidget(label_logo);
    horizontalLayout_header->addWidget(help);
    horizontalLayout_header->addWidget(minimize);
    horizontalLayout_header->addWidget(close);
    horizontalLayout_header->addWidget(occupying2);
    //设置对其方式
    horizontalLayout_header->setAlignment(label_logo,Qt::AlignLeft | Qt::AlignTop);
    horizontalLayout_header->setAlignment(help, Qt::AlignRight);

    //QVBoxLayout垂直布局
    QVBoxLayout* v_header = new QVBoxLayout();
    //将水平布局加入垂直布局中
    v_header->addLayout(horizontalLayout_header);
    v_header->setAlignment(horizontalLayout_header,Qt::AlignTop);

    //设置顶部Titlebar布局
    t->setLayout(v_header);


    //将布局添加到主窗口的垂直布局1中
    ui->verticalLayout->addWidget(t);

    ui->verticalLayout->addWidget(ui->stackedWidget);
    ui->verticalLayout->addWidget(ui->widget_botton);

    //内部控件间距
    ui->verticalLayout->setSpacing(0);
    //边距
    ui->verticalLayout->setMargin(0);

    //?
    ui->verticalLayout_6->setSizeConstraint(QLayout::SetFixedSize);
    //?
    centerWindow->setLayout(ui->verticalLayout);

    ui->widget_botton->setAutoFillBackground(true);
}

//首页
void MainWindow::createUI_page_front()
{
    ui->page_front->setFixedHeight(585);
    //打包按钮
    QPixmap p_btn;
    p_btn.load("/usr/share/cpktransform/images/btn_normal.png");
    btn_package = new Button("打CPK包", "/usr/share/cpktransform/images/btn", "",p_btn);
    btn_package->setEnabled(true);
    btn_package->setIcon(p_btn);
    btn_package->setIconSize(QSize(p_btn.width(), p_btn.height()));
    btn_package->setStyleSheet("QToolButton{border:1px groove gray;border-radius:5px; font-family:'Microsoft YaHei'; font-size:16px;border-style: flat;};");
    btn_package->setCursor(Qt::PointingHandCursor);
    connect(btn_package, SIGNAL(clicked()), this, SLOT(click_btn_package_button()));
    QPalette palette = btn_package->palette();
    palette.setColor(QPalette::Active,QPalette::ButtonText,QColor(240,250,250));
    btn_package->setPalette(palette);

    //转包按钮
    btn_transfer = new Button("转CPK包","/usr/share/cpktransform/images/btn", "",p_btn);
    btn_transfer->setEnabled(true);
    btn_transfer->setIcon(p_btn);
    btn_transfer->setIconSize(QSize(p_btn.width(), p_btn.height()));
    btn_transfer->setStyleSheet("QToolButton{border:1px groove gray;border-radius:5px; font-family:'Microsoft YaHei'; font-size:16px;border-style: flat;};");
    btn_transfer->setCursor(Qt::PointingHandCursor);
    connect(btn_transfer, SIGNAL(clicked()), this, SLOT(click_btn_transfer_button()));
    QPalette palette2 = btn_transfer->palette();
    palette2.setColor(QPalette::Active,QPalette::ButtonText,QColor(240,250,250));
    btn_transfer->setPalette(palette2);

    //占位标签（顶部/两按钮的间隔）
    QLabel* ocupy1 = new QLabel("");
    ocupy1->setFixedHeight(180);
    QLabel* ocupy2 = new QLabel("");
    ocupy2->setFixedHeight(50);

    //添加到布局中
    ui->verticalLayout_front->addWidget(ocupy1);
    ui->verticalLayout_front->addWidget(btn_package);
    ui->verticalLayout_front->addWidget(btn_transfer);
    ui->verticalLayout_front->addWidget(ocupy2);
    ui->verticalLayout_front->setAlignment(btn_package, Qt::AlignCenter);
    ui->verticalLayout_front->setAlignment(btn_transfer, Qt::AlignCenter);


    ui->widget_front->setAutoFillBackground(true);
    QString bck_front =QString("/usr/share/cpktransform/images/background_1.png");
    QPixmap pimmap_d2(bck_front);
    QPalette palette3;
    palette3.setBrush(ui->widget_front->backgroundRole(), QBrush(pimmap_d2));
    ui->widget_front->setPalette(palette3);
    ui->widget_front->setFixedWidth(pimmap_d2.width());
    ui->widget_front->setFixedHeight(pimmap_d2.height());

    ui->widget_botton_2->setAutoFillBackground(true);
    QPixmap pixmap1("/usr/share/cpktransform/images/background_2.png");
    QPalette   palette1;
    palette1.setBrush(ui->widget_botton_2->backgroundRole(),QBrush(pixmap1));
    ui->widget_botton_2->setPalette(palette1);
    ui->widget_botton_2->setFixedWidth(pixmap1.width());
    ui->widget_botton_2->setFixedHeight(pixmap1.height());
}

//解压->“选择deb/rpm包” 页 page
void MainWindow::createUI_page1()
{
    strQToolButton = "QToolButton {\
           color:rgb(105,105,105);\
            border: 1px solid gray;\
            border-radius: 1px;\
            background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,\
                                              stop: 0 #f6f7fa, stop: 1 #dadbde);\
            min-width: 80px;\
        }\
    \
        QToolButton:pressed {\
            background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,\
                                              stop: 0 #dadbde, stop: 1 #f6f7fa);\
        }\
    \
        QToolButton:flat {\
            border: none; /*  没有边框的按钮 */\
        }\
    \
        QToolButton:default {\
            border-color: navy; /* 使得按钮显示变得更加突出 */\
        }\
    \
     \
           QToolButton:open { /* when the button has its menu open */\
            background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,\
                                              stop: 0 #dadbde, stop: 1 #f6f7fa);\
        }\
    \
        QToolButton::menu-indicator {\
            image: url(menu_indicator.png);\
            subcontrol-origin: padding;\
            subcontrol-position: bottom right;\
        }";

        //转包-解压后-详情页的-选择执行路径按钮
    control_xml_2 = new Xml(ui->gridLayout_area);
    QToolButton * tExec = new QToolButton();
    tExec->setFixedSize(130,27);
    tExec->setStyleSheet(strQToolButton);
    tExec->setText("选择执行程序路径");
    tExec->setCursor(Qt::PointingHandCursor);
    connect( tExec, SIGNAL(clicked()), this, SLOT(click_btn_exec()));

    QHBoxLayout* hExec = new QHBoxLayout();
    hExec->addWidget(control_xml_2->lExec);
    hExec->addWidget(tExec);
    hExec->setAlignment(tExec, Qt::AlignLeft);
    control_xml_2->gbox_info->addLayout(hExec,7,1,1,1);

    //选择icon按钮
    QToolButton* tIcon = new QToolButton();
    tIcon->setFixedSize(130,27);
    tIcon->setStyleSheet(strQToolButton);
    tIcon->setText("选择图标");
    tIcon->setCursor(Qt::PointingHandCursor);
    connect( tIcon, SIGNAL(clicked()), this, SLOT(click_btn_icon()));

    //    gbox_details->addWidget(tldesc_en,3,1,1,1);
//    QToolButton* tPic1 = new QToolButton();
//    tPic1->setFixedSize(130,27);
//    tPic1->setStyleSheet(strQToolButton);
//    tPic1->setText("添加截图");
//    tPic1->setCursor(Qt::PointingHandCursor);
//    connect( tPic1, SIGNAL(clicked()), this, SLOT(click_btn_pic()));

    QLabel* ldesktop = new QLabel("启动器：     ");
    ldesktop->setStyleSheet("QLabel{border-width:0px;}");

    QToolButton* tDesktop = new QToolButton();
    tDesktop->setFixedSize(130,27);
    tDesktop->setStyleSheet(strQToolButton);
    tDesktop->setText("选择启动器");
    tDesktop->setCursor(Qt::PointingHandCursor);
    connect( tDesktop, SIGNAL(clicked()), this, SLOT(click_btn_desktop()));

    QHBoxLayout* hIcon = new QHBoxLayout();
    hIcon->addWidget(control_xml_2->icon_le);
    hIcon->addWidget(tIcon);
//    hIcon->addWidget(tPic1);
    hIcon->setAlignment(tIcon, Qt::AlignLeft);
    control_xml_2->gbox_info->addLayout(hIcon,8,1,1,1);

    QHBoxLayout* hDesktop = new QHBoxLayout();
    hDesktop->addWidget(ldesktop);
    hDesktop->addWidget(control_xml_2->desktop_le);
    hDesktop->addWidget(tDesktop);
    hDesktop->setAlignment(ldesktop, Qt::AlignLeft);
    hDesktop->setAlignment(control_xml_2->desktop_le, Qt::AlignLeft);
    hDesktop->setAlignment(tDesktop, Qt::AlignLeft);
    control_xml_2->gbox_info->addLayout(hDesktop,9,0,1,3);
    control_xml_2->gbox_info->setAlignment(hDesktop, Qt::AlignLeft);



    //?
    ui->page->setFixedHeight(585);

    //转包-解压按钮
    QPixmap p_btn;
    p_btn.load("/usr/share/cpktransform/images/btn_normal.png");
    btn = new Button("解     压", "/usr/share/cpktransform/images/btn", "",p_btn);
    btn->setEnabled(false);
    btn->setIcon(p_btn);
    btn->setIconSize(QSize(p_btn.width(),p_btn.height()));
    btn->setFixedSize(p_btn.width(),p_btn.height());
    btn->setStyleSheet("QToolButton{border:1px groove gray;border-radius:5px; font-family:'Microsoft YaHei'; font-size:16px;border-style: flat;};");
    btn->setCursor(Qt::PointingHandCursor);

    //QLineEdit是单行文本框。
    //QTextEdit是多行文本框。?
    script_line = new CLineEdit();
    script_edit = new QTextEdit();

    connect(btn, SIGNAL(clicked()), this, SLOT(click_btnbutton()));
    QPalette palette = btn->palette();
    palette.setColor(QPalette::Active,QPalette::ButtonText,QColor(240,250,250));
    btn->setPalette(palette);


    ui->horizontalLayout_down->addWidget(btn);
    ui->horizontalLayout_down->setAlignment(btn, Qt::AlignCenter);

    //转包-按钮
    QString str =  "/usr/share/cpktransform/images/add_package_normal.png";
    QPixmap mypixmap;
    mypixmap.load(str);
    tlb = new Button("","/usr/share/cpktransform/images/add_package", "",mypixmap);
    tlb->setFixedSize(mypixmap.width(),mypixmap.height());
    tlb->setIcon(mypixmap);
    tlb->setIconSize(QSize(mypixmap.width(),mypixmap.height()));
    tlb->setStyleSheet("QToolButton{border:0px ;border-radius:0px;}");
    tlb->setCursor(Qt::PointingHandCursor);
    connect(tlb, SIGNAL(clicked()), this, SLOT(click_tlbbutton()));


    //占位标签
    QLabel* occupy = new QLabel("");
    occupy->setFixedHeight(160);

    //转包-返回按钮
    QPixmap p_previous;
    p_previous.load("/usr/share/cpktransform/images/arrow_left.png");
    QToolButton* previous = new QToolButton();
    previous->setText("回到首页");
    previous->setStyleSheet("QToolButton{border:1px groove gray;border-radius:5px; font-family:'Microsoft YaHei'; font-size:13px;border-style: flat;color:rgb(245,245,245)};");
//         previous->setStyleSheet("QToolButton{border:1px groove gray;border-radius:5px; font-family:'文泉驿等宽微米黑'; font-size:13px;border-style: flat;color:rgb(245,245,245)};");
//    文泉驿等宽微米黑
    previous->setCursor(Qt::PointingHandCursor);
    previous->setFixedSize(80,20);
    //previous->setIcon(p_previous);
    //previous->setIconSize(QSize(43,43));
    connect(previous, SIGNAL(clicked()), this, SLOT(click_previousbutton()));

    //布局
    ui->verticalLayout__up->addWidget(occupy);
    ui->verticalLayout__up->addWidget(tlb);
    ui->verticalLayout__up->addWidget(previous);
    ui->verticalLayout__up->setAlignment(previous, Qt::AlignCenter);
    ui->verticalLayout__up->setAlignment(tlb, Qt::AlignCenter);


    ui->widget_up->setAutoFillBackground(true);
    QPixmap pixmap("/usr/share/cpktransform/images/background_1.png");
    QPalette   palette0;
    palette0.setBrush(ui->widget_up->backgroundRole(),QBrush(pixmap));
    ui->widget_up->setPalette(palette0);
    ui->widget_up->setFixedWidth(pixmap.width());
    ui->widget_up->setFixedHeight(pixmap.height());

    ui->widget_down->setAutoFillBackground(true);
    QPixmap pixmap1("/usr/share/cpktransform/images/background_2.png");
    QPalette   palette1;
    palette1.setBrush(ui->widget_down->backgroundRole(),QBrush(pixmap1));
    ui->widget_down->setPalette(palette1);
    ui->widget_down->setFixedWidth(pixmap1.width());
    ui->widget_down->setFixedHeight(pixmap1.height());
}

    //转包-解压后-应用详情（打包）页
void MainWindow::createUI_page2()
{
    ui->page_2->setFixedHeight(585);
    //分割线
    ui->line_2->setFixedWidth(142);
    ui->line_2->setFixedHeight(1);
    ui->line_2->setStyleSheet("background-color:rgb(172,249,255)");
    //图标按钮
    ui->toolButton->setFixedSize(158,40);
    ui->toolButton->setVisible(false);

    ui->page_11->setFixedSize(535,522);
    ui->page_12->setFixedSize(535,522);
    //包信息文本框的样式
    QString vertical_text = QString("QScrollBar:vertical"
                                    "{"
                                    "width:8px;"
                                    "background:rgba(0,0,0,0%);"
                                    "margin:0px,0px,0px,0px;"
                                    "padding-top:9px;"
                                    "padding-bottom:9px;"
                                    "}"
                                    "QScrollBar::handle:vertical"
                                    "{"
                                    "width:8px;"
                                    "background:rgba(0,150,237,25%);"
                                    " border-radius:4px;"
                                    "min-height:20;"
                                    "}"
                                    "QScrollBar::handle:vertical:hover"
                                    "{"
                                    "width:8px;"
                                    "background:rgba(0,150,237,60%);"
                                    " border-radius:4px;"
                                    "min-height:20;"
                                    "}"
                                    "QScrollBar::add-line:vertical"
                                    "{"
                                    "height:9px;width:8px;"
                                   "border-image:url(/usr/share/cpktransform/images/down_normal.png);"
                                    "subcontrol-position:bottom;"
                                    "}"
                                    "QScrollBar::sub-line:vertical"
                                    "{"
                                    "height:9px;width:8px;"
                                    "border-image:url(/usr/share/cpktransform/images/up_normal.png);"
                                    "subcontrol-position:top;"
                                    "}"
                                    "QScrollBar::add-line:vertical:hover"
                                    "{"
                                    "height:9px;width:8px;"
                                    "border-image:url(/usr/share/cpktransform/images/down_pressed.png);"
                                    "subcontrol-position:bottom;"
                                    "}"
                                    "QScrollBar::sub-line:vertical:hover"
                                    "{"
                                    "height:9px;width:8px;"
                                    "border-image:url(/usr/share/cpktransform/images/up_pressed.png);"
                                    "subcontrol-position:top;"
                                    "}"
                                    "QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical"
                                    "{"
                                    "background:rgba(77,0,0,10%);"
                                    "border-radius:4px;"
                                    "}");
    //包信息文本框
    ui->textEdit_help_2->verticalScrollBar()->setStyleSheet(vertical_text);
    ui->textEdit_help_2->setStyleSheet("border:0px;color:rgb(105,105,105);background-color:rgb(245,245,245);");
    ui->textEdit_help_2->setFixedSize(535,510);
    ui->textEdit_help_2->setReadOnly(true);

    //打开文件（如果失败，提示错误）
    QFile file("/usr/share/cpktransform/usermanual_conversion.txt");
    if ( !file.open(QIODevice::ReadOnly | QIODevice::Text) )
    {qDebug()<< "the folder has no usermanual";}

    //读文件流（使用utf8编码），赋值给包信息文本框
    QTextCodec * code = QTextCodec::codecForName("utf8");
    QTextStream stream(&file);
    stream.setCodec(code);//对输出流的设置
    while (stream.atEnd() == 0) {
        ui->textEdit_help_2->setText(stream.readAll());
    }
    //ui->centralWidget->setStyleSheet("QFrame {border:1px solid black;}");

    //包图标
    QPixmap  p;
    p.load("/usr/share/cpktransform/images/package.png");
    ui->toolButton_icon->setIcon(QIcon(p));
    ui->toolButton_icon->setFixedHeight(48);
    //此处设置宽度导致label大小不能随内容多少进行改变
    //    ui->label_22->setFixedWidth(70);
    ui->toolButton_10->setFixedSize(100,27);
    ui->toolButton_11->setFixedSize(80,27);
    ui->lineEdit_target_2->setFixedHeight(27);
    ui->lineEdit_target_2->setFixedWidth(410);
    connect(ui->toolButton_11, SIGNAL(clicked()), this, SLOT(click_transbutton()));
    connect(ui->toolButton_10, SIGNAL(clicked()), this, SLOT(click_btn_selbutton()));

    //左背景图
    ui->widget->setAutoFillBackground(true);
    QPixmap pixmap2("/usr/share/cpktransform/images/backgroud_2_left.png");
    QPalette   palette1;
    palette1.setBrush(ui->widget->backgroundRole(),QBrush(pixmap2));
    ui->widget->setPalette(palette1);
    ui->widget->setFixedWidth(pixmap2.width());
    ui->widget->setFixedHeight(pixmap2.height());


    ui->page->setAutoFillBackground(true);
    QPalette p1=ui->page_2->palette();
    p1.setColor(QPalette::Window,QColor(250, 250, 250));
    ui->page->setPalette(p1);

    ui->page_2->setAutoFillBackground(true);
    QPalette p2=ui->page_2->palette();
    p2.setColor(QPalette::Window,QColor(255,255,255));
    ui->page_2->setPalette(p2);

    ui->page_3->setAutoFillBackground(true);
    QPalette p3=ui->page_3->palette();
    p3.setColor(QPalette::Window,QColor(255, 245, 238));
    ui->page_3->setPalette(p3);

    ui->page_4->setAutoFillBackground(true);
    QPalette p4=ui->page_4->palette();
    p4.setColor(QPalette::Window,QColor(255, 245, 238));
    ui->page_4->setPalette(p4);

    ui->widget_b->setAutoFillBackground(true);
    QPalette p3b=ui->widget_b->palette();
    p3b.setColor(QPalette::Window,QColor(205,197,191 ));
    ui->widget_b->setPalette(p3b);

    //page_2 right
    ui->stackedWidget_3->setAutoFillBackground(true);
    QPixmap pixmap3("/usr/share/cpktransform/images/background_2_right.png");
    QPalette   palette3;
    palette3.setBrush(ui->stackedWidget_3->backgroundRole(),QBrush(pixmap3));
    ui->stackedWidget_3->setPalette(palette3);
    ui->stackedWidget_3->setFixedWidth(pixmap3.width());
    ui->stackedWidget_3->setFixedHeight(pixmap3.height());

    ui->scrollArea_2->setAutoFillBackground(true);
    ui->vertical_dig->setStyleSheet("background-color:rgb(245,245,245)");

    //page_2 right stacked 123456 btn
    QPixmap p_dig;
    p_dig.load("/usr/share/cpktransform/images/1_sel.png");
    dig1 = new Button("", "/usr/share/cpktransform/images/1", "基本信息", p_dig);
    dig1->is_release = true;
    dig1->setIcon(p_dig);
    dig1->setIconSize(QSize(p_dig.width(),p_dig.height()));
    dig1->setFixedSize(p_dig.width(),p_dig.height());
    dig1->setStyleSheet("QToolButton{border:1px groove gray;border-radius:5px; font-family:'Microsoft YaHei'; font-size:16px;border-style: flat;};");
    dig1->setCursor(Qt::PointingHandCursor);
    connect(dig1, SIGNAL(clicked()),this,SLOT(set_scrollbar_value_by_dig1()));

    p_dig.load("/usr/share/cpktransform/images/2_normal.png");
    dig2 = new Button("", "/usr/share/cpktransform/images/2", "应用详情",p_dig);
    dig2->setIcon(p_dig);
    dig2->setIconSize(QSize(p_dig.width(),p_dig.height()));
    dig2->setFixedSize(p_dig.width(),p_dig.height());
    dig2->setStyleSheet("QToolButton{border:1px groove gray;border-radius:5px; font-family:'Microsoft YaHei'; font-size:16px;border-style: flat;};");
    dig2->setCursor(Qt::PointingHandCursor);
    connect(dig2, SIGNAL(clicked()),this,SLOT(set_scrollbar_value_by_dig2()));

    p_dig.load("/usr/share/cpktransform/images/3_normal.png");
    dig3 = new Button("", "/usr/share/cpktransform/images/3", "应用权限",p_dig);
    dig3->setIcon(p_dig);
    dig3->setIconSize(QSize(p_dig.width(),p_dig.height()));
    dig3->setFixedSize(p_dig.width(),p_dig.height());
    dig3->setStyleSheet("QToolButton{border:1px groove gray;border-radius:5px; font-family:'Microsoft YaHei'; font-size:16px;border-style: flat;};");
    dig3->setCursor(Qt::PointingHandCursor);
    connect(dig3, SIGNAL(clicked()),this,SLOT(set_scrollbar_value_by_dig3()));

    p_dig.load("/usr/share/cpktransform/images/4_normal.png");
    dig4 = new Button("", "/usr/share/cpktransform/images/4", "作者信息",p_dig);
    dig4->setIcon(p_dig);
    dig4->setIconSize(QSize(p_dig.width(),p_dig.height()));
    dig4->setFixedSize(p_dig.width(),p_dig.height());
    dig4->setStyleSheet("QToolButton{border:1px groove gray;border-radius:5px; font-family:'Microsoft YaHei'; font-size:16px;border-style: flat;};");
    dig4->setCursor(Qt::PointingHandCursor);
    connect(dig4, SIGNAL(clicked()),this,SLOT(set_scrollbar_value_by_dig4()));

    p_dig.load("/usr/share/cpktransform/images/5_normal.png");
    dig5 = new Button("", "/usr/share/cpktransform/images/5", "其他信息",p_dig);
    dig5->setIcon(p_dig);
    dig5->setIconSize(QSize(p_dig.width(),p_dig.height()));
    dig5->setFixedSize(p_dig.width(),p_dig.height());
    dig5->setStyleSheet("QToolButton{border:1px groove gray;border-radius:5px; font-family:'Microsoft YaHei'; font-size:16px;border-style: flat;};");
    dig5->setCursor(Qt::PointingHandCursor);
    connect(dig5, SIGNAL(clicked()),this,SLOT(set_scrollbar_value_by_dig5()));

    p_dig.load("/usr/share/cpktransform/images/6_normal.png");
    dig6 = new Button("", "/usr/share/cpktransform/images/6", "脚本信息",p_dig);
    dig6->setIcon(p_dig);
    dig6->setIconSize(QSize(p_dig.width(),p_dig.height()));
    dig6->setFixedSize(p_dig.width(),p_dig.height());
    dig6->setStyleSheet("QToolButton{border:1px groove gray;border-radius:5px; font-family:'Microsoft YaHei'; font-size:16px;border-style: flat;};");
    dig6->setCursor(Qt::PointingHandCursor);
    connect(dig6, SIGNAL(clicked()),this,SLOT(set_scrollbar_value_by_dig6()));

    connect(ui->toolButton, SIGNAL(clicked()), this, SLOT(click_button()));
    connect(ui->toolButton_icon, SIGNAL(clicked()), this, SLOT(click_button_icon()));

    occupying_dig  = new QLabel("");
    occupying_dig->setFixedSize(22,3);

#if 1
    ui->verticalLayout_dig->addWidget(dig1);
    ui->verticalLayout_dig->addWidget(dig2);
    ui->verticalLayout_dig->addWidget(dig3);
    ui->verticalLayout_dig->addWidget(dig4);
    ui->verticalLayout_dig->addWidget(dig5);
    ui->verticalLayout_dig->addWidget(dig6);
    ui->verticalLayout_dig->addWidget(occupying_dig);
    ui->verticalLayout_dig->setAlignment(dig1,Qt::AlignBottom);
#endif

    ui->scrollAreaWidgetContents->setStyleSheet("background-color:rgb(245,245,245);");
    //右侧滚动条
    QScrollBar* slider = new QScrollBar(Qt::Vertical, ui->scrollAreaWidgetContents);
    ui->scrollArea->setVerticalScrollBar(slider);
    ui->scrollArea->verticalScrollBar()->setStyleSheet(vertical_text);
    ui->scrollArea->verticalScrollBar()->setTracking(true);
    connect(ui->scrollArea->verticalScrollBar(),SIGNAL(valueChanged(int)),
            this, SLOT(scrollbar_value_changed(int)));

    connect(control_xml_2->sProtocol, SIGNAL(currentIndexChanged(int)), this, SLOT(process_Protocol2(int)));
    connect( control_xml_2->grp1, SIGNAL(buttonClicked (int)), this, SLOT(button_desktop_Judge2(int)));
    connect( control_xml_2->grp2, SIGNAL(buttonClicked (int)), this, SLOT(button_patch_Judge2(int)));
    connect( control_xml_2->grp3, SIGNAL(buttonClicked (int)), this, SLOT(button_essential_Judge2(int)));

    //buju-6
    QPixmap pscript;
    pscript.load("/usr/share/cpktransform/images/btn_6.png");
    Label* script = new Label("脚本信息",pscript);
    script->setPixmap(pscript);
    QGridLayout* gbox_script = new QGridLayout();
    QLabel* in =    new QLabel("脚本名称1：");
    in->setStyleSheet("QLabel{border-width:0px;}");
    QLabel* in_text = new QLabel("脚本内容：");
    in_text->setStyleSheet("QLabel{border-width:0px;}");
    if(!script_line)
        script_line = new CLineEdit();
    if(!script_edit)
        script_edit = new QTextEdit();
    script_line->setFixedHeight(27);
    script_line->setFixedWidth(340);
    script_line->setPlaceholderText(" 格式为：软件名.install ");
    script_line->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    script_edit->setStyleSheet("QTextEdit{background:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    script_edit->verticalScrollBar()->setStyleSheet(vertical_text);
    script_edit->setFixedWidth(340);
    script_edit->setText("#! /usr/bin/bash\n\
  \n\
  #在Deb解包之前，将会运行该脚本\n\
  pre_install()\n\
  {\n\
    :\n\
  } \n\
  #负责完成安装包时的配置\n\
  post_install()\n\
  {\n\
    :\n\
  } \n\
  #负责停止与软件包相关联的daemon服务\n\
  pre_remove()\n\
  {\n\
    :\n\
  } \n\
  #负责修改软件包连接或文件关联\n\
  post_remove()\n\
  {\n\
    :\n\
  } \n\
  pre_upgrade()\n\
  {\n\
    :\n\
  } \n\
  post_upgrade()\n\
  {\n\
    :\n\
  } \n\
  pre_downgrade()\n\
  {\n\
     :\n\
  } \n\
  post_upgrade()\n\
  {\n\
    :\n\
  } \n\
                          ");
    gbox_script->addWidget(in, 0,0,1,1);
    gbox_script->addWidget(script_line, 0,1,1,1);
    gbox_script->addWidget(in_text,1,0,1,1);
    gbox_script->addWidget(script_edit,1,1,1,1);
    gbox_script->setAlignment(in_text, Qt::AlignTop);
    gbox_script->setAlignment(script_line,Qt::AlignLeft);
    gbox_script->setAlignment(script_edit,Qt::AlignLeft);

    QWidget* s_script= new QWidget;
    s_script->setFixedSize(470,550);
    s_script->setLayout(gbox_script);
    s_script->setStyleSheet("color:rgb(105,105,105);border:1px solid #E5E5E5;border-radius:1px");//mencius
    s_script->setAutoFillBackground(true);
    QLabel* occupying_4 = new QLabel("");
    occupying_4->setFixedHeight(10);
    ui->gridLayout_area->addWidget(occupying_4, 15, 0,1,1);
    ui->gridLayout_area->addWidget(script,16,0,1,1);
    ui->gridLayout_area->addWidget(s_script,17,0,1,1);
    ui->gridLayout_area->setAlignment(gbox_script,Qt::AlignLeft);
     //进入界面时，滚动条不滚动
    this->progreddBarEnable(false);
}

//打包完成成功界面 page_3
void MainWindow::createUI_page3()
{
    ui->page_3->setFixedHeight(585);
    label_logo->setStyleSheet("color:rgb(1,44,67);font-size:13px ");
    ui->widget_up_2->setAutoFillBackground(true);
    QString bck_up_text =QString("/usr/share/cpktransform/images/bckground_up.png");
    QPixmap pimmap_d1(bck_up_text);
    QPalette palette1;
    palette1.setBrush(ui->widget_up_2->backgroundRole(), QBrush(pimmap_d1));
    ui->widget_up_2->setPalette(palette1);
    ui->widget_up_2->setFixedWidth(pimmap_d1.width());
    ui->widget_up_2->setFixedHeight(pimmap_d1.height());

    ui->widget_down_2->setAutoFillBackground(true);
    QString bck_down_text =QString("/usr/share/cpktransform/images/bckground_down.png");
    QPixmap pimmap_d2(bck_down_text);
    QPalette palette2;
    palette2.setBrush(ui->widget_down_2->backgroundRole(), QBrush(pimmap_d2));
    ui->widget_down_2->setPalette(palette2);
    ui->widget_down_2->setFixedWidth(pimmap_d2.width());
    ui->widget_down_2->setFixedHeight(pimmap_d2.height());

    //verticalLayout_down_2
    pix_tips = new QLabel();

    tips = new QLabel();
    tips->setText("");
    tips->setStyleSheet("QLabel{border:1px groove gray;border-radius:5px; font-family:'Microsoft YaHei'; font-size:16px;border-style: flat;color:white};");

    QPixmap  pTrans;
    pTrans.load("/usr/share/cpktransform/images/btn_normal.png");
    btn_trans = new Button("回到首页","/usr/share/cpktransform/images/btn", "",pTrans);
    btn_trans->setEnabled(true);
    btn_trans->setIcon(pTrans);
    btn_trans->setIconSize(QSize(pTrans.width(),pTrans.height()));
    btn_trans->setFixedSize(pTrans.width(),pTrans.height());
    btn_trans->setStyleSheet("QToolButton{border:1px groove gray;border-radius:5px; font-family:'Microsoft YaHei'; font-size:16px;border-style: flat;};");
    btn_trans->setCursor(Qt::PointingHandCursor);
    connect(btn_trans, SIGNAL(clicked()), this, SLOT(click_btn_transbutton()));
    QPalette palette = btn_trans->palette();
    palette.setColor(QPalette::Active,QPalette::ButtonText,QColor(240,250,250));
    btn_trans->setPalette(palette);

    QPixmap pOpenDir;
    pOpenDir.load("/usr/share/cpktransform/images/btn_normal.png");
    btn_opendir = new Button("打开目录","/usr/share/cpktransform/images/btn", "",pOpenDir);

    btn_opendir->setEnabled(true);
    btn_opendir->setIcon(pOpenDir);
    btn_opendir->setIconSize(QSize(pTrans.width(),pTrans.height()));
    btn_opendir->setFixedSize(pTrans.width(),pTrans.height());
    btn_opendir->setStyleSheet("QToolButton{border:1px groove gray;border-radius:5px; font-family:'Microsoft YaHei'; font-size:16px;border-style: flat;};");
    btn_opendir->setCursor(Qt::PointingHandCursor);
     connect(btn_opendir, SIGNAL(clicked()), this, SLOT(click_btn_opendirbutton()));
    QPalette palette0 = btn_trans->palette();
    palette0.setColor(QPalette::Active,QPalette::ButtonText,QColor(240,250,250));
    btn_opendir->setPalette(palette0);

    occupying_page_3 = new QLabel();

    QString vertical_text = QString("QScrollBar:vertical"
                                    "{"
                                    "width:8px;"
                                    "background:rgba(0,0,0,0%);"
                                    "margin:0px,0px,0px,0px;"
                                    "padding-top:9px;"
                                    "padding-bottom:9px;"
                                    "}"
                                    "QScrollBar::handle:vertical"
                                    "{"
                                    "width:8px;"
                                    "background:rgba(0,150,237,25%);"
                                    " border-radius:4px;"
                                    "min-height:20;"
                                    "}"
                                    "QScrollBar::handle:vertical:hover"
                                    "{"
                                    "width:8px;"
                                    "background:rgba(0,150,237,60%);"
                                    " border-radius:4px;"
                                    "min-height:20;"
                                    "}"
                                    "QScrollBar::add-line:vertical"
                                    "{"
                                    "height:9px;width:8px;"
                                   "border-image:url(/usr/share/cpktransform/images/down_normal.png);"
                                    "subcontrol-position:bottom;"
                                    "}"
                                    "QScrollBar::sub-line:vertical"
                                    "{"
                                    "height:9px;width:8px;"
                                    "border-image:url(/usr/share/cpktransform/images/up_normal.png);"
                                    "subcontrol-position:top;"
                                    "}"
                                    "QScrollBar::add-line:vertical:hover"
                                    "{"
                                    "height:9px;width:8px;"
                                    "border-image:url(/usr/share/cpktransform/images/down_pressed.png);"
                                    "subcontrol-position:bottom;"
                                    "}"
                                    "QScrollBar::sub-line:vertical:hover"
                                    "{"
                                    "height:9px;width:8px;"
                                    "border-image:url(/usr/share/cpktransform/images/up_pressed.png);"
                                    "subcontrol-position:top;"
                                    "}"
                                    "QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical"
                                    "{"
                                    "background:rgba(77,0,0,10%);"
                                    "border-radius:4px;"
                                    "}");
    textEdit_errorInfoDes = new QTextEdit();
    textEdit_errorInfoDes->setFixedHeight(150);
    textEdit_errorInfoDes->setFixedWidth(340);
    textEdit_errorInfoDes->setStyleSheet("QTextEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    textEdit_errorInfoDes->verticalScrollBar()->setStyleSheet(vertical_text );
    textEdit_errorInfoDes->setReadOnly(true);

    ui->verticalLayout_down_2->addWidget(pix_tips);
    ui->verticalLayout_down_2->addWidget(tips);
    ui->verticalLayout_down_2->addWidget(textEdit_errorInfoDes);
    ui->verticalLayout_down_2->addWidget(btn_trans);
    ui->verticalLayout_down_2->addWidget(btn_opendir);
    ui->verticalLayout_down_2->addWidget(occupying_page_3);
    ui->verticalLayout_down_2->setAlignment(pix_tips, Qt::AlignCenter);
    ui->verticalLayout_down_2->setAlignment(tips, Qt::AlignCenter);
    ui->verticalLayout_down_2->setAlignment(btn_trans, Qt::AlignCenter);
    ui->verticalLayout_down_2->setAlignment(btn_opendir, Qt::AlignCenter);
    ui->verticalLayout_down_2->setAlignment(textEdit_errorInfoDes, Qt::AlignCenter);
}

//打包->“选择源文件夹”页 page_10
void MainWindow::createUI_page4()
{
    ui->page_10->setFixedHeight(585);
    QString str =  "/usr/share/cpktransform/images/add_folder_normal.png";
    QPixmap mypixmap;
    mypixmap.load(str);

    tlb2 = new Button("","/usr/share/cpktransform/images/add_folder", "",mypixmap);
    tlb2->setFixedSize(mypixmap.width(),mypixmap.height());
    tlb2->setIcon(mypixmap);
    tlb2->setIconSize(QSize(mypixmap.width(),mypixmap.height()));
    tlb2->setStyleSheet("QToolButton{border:0px ;border-radius:0px;}");
    tlb2->setCursor(Qt::PointingHandCursor);

    QLabel* occupy = new QLabel("");
    occupy->setFixedHeight(160);

    QPixmap p_previous;
    p_previous.load("/usr/share/cpktransform/images/arrow_left.png");
     QToolButton* previous = new QToolButton();
     previous->setText("回到首页");
    previous->setStyleSheet("QToolButton{border:1px groove gray;border-radius:5px; font-family:'Microsoft YaHei'; font-size:13px;border-style: flat;color:rgb(245,245,245)};");
    previous->setCursor(Qt::PointingHandCursor);
    previous->setFixedSize(80,20);
    //previous->setIcon(p_previous);
    //previous->setIconSize(QSize(43,43));
    connect(previous, SIGNAL(clicked()), this, SLOT(click_previousbutton()));

    ui->verticalLayout__up_2->addWidget(occupy);
    ui->verticalLayout__up_2->addWidget(tlb2);
    ui->verticalLayout__up_2->addWidget(previous);
    ui->verticalLayout__up_2->setAlignment(previous, Qt::AlignCenter);
    ui->verticalLayout__up_2->setAlignment(tlb2, Qt::AlignCenter);
    connect(tlb2, SIGNAL(clicked()), this, SLOT(click_tlb2button()));

}

//page_4 打包详情页
void MainWindow::createUI_page5()
{
    //背景上
    ui->widget_up_3->setAutoFillBackground(true);
    QPixmap pixmap("/usr/share/cpktransform/images/background_1.png");
    QPalette   palette0;
    palette0.setBrush(ui->widget_up_3->backgroundRole(),QBrush(pixmap));
    ui->widget_up_3->setPalette(palette0);
    ui->widget_up_3->setFixedWidth(pixmap.width());
    ui->widget_up_3->setFixedHeight(pixmap.height());
    //背景下
    ui->widget_down_3->setAutoFillBackground(true);
    QPixmap pixmap1("/usr/share/cpktransform/images/background_2.png");
    QPalette   palette1;
    palette1.setBrush(ui->widget_down_3->backgroundRole(),QBrush(pixmap1));
    ui->widget_down_3->setPalette(palette1);
    ui->widget_down_3->setFixedWidth(pixmap1.width());
    ui->widget_down_3->setFixedHeight(pixmap1.height());

    ui->page_4->setFixedHeight(585);
    ui->label_10->setFixedSize(22,522);
    ui->label_10->setStyleSheet("background-color:rgb(245,245,245)");
    ui->scrollAreaWidgetContents_2->setStyleSheet("background-color:rgb(245,245,245);");

    strQToolButton2 = "QToolButton {\
                color:rgb(245,245,245);\
                 border: 0px solid #8f8f91;\
                 border-radius: 0px;\
                 min-width: 80px;\
             }\
         \
             QToolButton:pressed {\
                color:rgb(105,105,105);\
                 background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,\
                                                   stop: 0 #dadbde, stop: 1 #f6f7fa);\
             }\
         \
             QToolButton:flat {\
                 border: none; /*  没有边框的按钮 */\
             }\
         \
             QToolButton:default {\
                 border-color: navy; /* 使得按钮显示变得更加突出 */\
             }\
         \
          \
                QToolButton:open { /* when the button has its menu open */\
                 background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,\
                                                   stop: 0 #dadbde, stop: 1 #f6f7fa);\
             }\
         \
             QToolButton::menu-indicator {\
                 image: url(menu_indicator.png);\
                 subcontrol-origin: padding;\
                 subcontrol-position: bottom right;\
             }";
    //背景左
    ui->widget_7->setAutoFillBackground(true);
    QPixmap pixmap2("/usr/share/cpktransform/images/backgroud_2_left.png");
    QPalette   palette2;
    palette2.setBrush(ui->widget_7->backgroundRole(),QBrush(pixmap2));
    ui->widget_7->setPalette(palette2);
    ui->widget_7->setFixedWidth(pixmap2.width());
    ui->widget_7->setFixedHeight(pixmap2.height());
    //背景下
    ui->widget_8->setAutoFillBackground(true);
    QPixmap pixmap4("/usr/share/cpktransform/images/background_2_bottom.png");
    QPalette   palette4;
    palette4.setBrush(ui->widget_8->backgroundRole(),QBrush(pixmap4));
    ui->widget_8->setPalette(palette4);
    ui->widget_8->setFixedWidth(pixmap4.width());
    ui->widget_8->setFixedHeight(pixmap4.height());
    //背景右
    ui->widget_3->setAutoFillBackground(true);
    QPixmap pixmap3("/usr/share/cpktransform/images/background_2_right.png");
    QPalette   palette3;
    palette3.setBrush(ui->widget_3->backgroundRole(),QBrush(pixmap3));
    ui->widget_3->setPalette(palette3);
    ui->widget_3->setFixedWidth(pixmap3.width());
    ui->widget_3->setFixedHeight(pixmap3.height());

    ui->page_6->setFixedSize(535,522);
    ui->page_7->setFixedSize(530,522);
    ui->page_8->setFixedSize(530,522);
    ui->page_9->setFixedSize(537,522);
    //ui->widget_5->setStyleSheet("border:0px;");
    ui->widget_6->setStyleSheet("color:rgb(105,105,105);border:1px solid #E5E5E5;border-radius:1px;background-color:rgb(245,245,245)");
    ui->widget_5->setFixedWidth(470);
    ui->widget_6->setFixedWidth(470);
    //    ui->label_11->setFixedWidth(92);
    ui->stackedWidget_2->setStyleSheet("border:0px solid gray; border-radius:2px");
    ui->stackedWidget_2->setFixedSize(pixmap3.width(),pixmap3.height());
    ui->toolButton_2->setFixedSize(156,40);
    ui->toolButton_3->setFixedSize(156,40);
    ui->toolButton_4->setFixedSize(156,40);
    ui->toolButton_8->setFixedSize(80,27);
    ui->toolButton_9->setFixedSize(156,40);
    ui->toolButton_9->setVisible(false);
    ui->toolButton_6->setFixedSize(100,27);
    ui->stackedWidget_2->setCurrentIndex(1);
    ui->toolButton_2->setStyleSheet("QToolButton {\
                                  color:rgb(105,105,105);\
                                  background-color:rgb(245,245,245);\
                                   border: 0px solid #8f8f91;\
                                   border-radius: 0px;\
                               }");

    ui->label_tip_desktop->setStyleSheet("border:0px;color:rgb(105,105,105);");
    ui->label_tip_install->setStyleSheet("border:0px;color:rgb(105,105,105);");
    ui->label_tip_xml->setStyleSheet("border:0px;color:rgb(105,105,105);");
#if 0
    ui->label_tip_xml_2->setFixedSize(450,27);
    ui->label_tip_desktop_2->setFixedSize(450,27);
    ui->label_tip_install_2->setFixedSize(450,27);
    ui->label_tip_filelist->setFixedSize(450,27);
    ui->label_tip_xml_2->setStyleSheet("color:rgb(105,105,105);");
    ui->label_tip_desktop_2->setStyleSheet("color:rgb(105,105,105);");
    ui->label_tip_install_2->setStyleSheet("color:rgb(105,105,105);");
    ui->label_tip_filelist->setStyleSheet("color:rgb(105,105,105);");
#endif
    //“基本信息” “安装脚本”  “菜单启动器” 的 生成文件 重置 按钮
    ui->toolButton_Generate_Xml->setFixedSize(65,25);
    ui->toolButton_Undo_Xml->setFixedSize(65,25);
    ui->toolButton_Generate_Script->setFixedSize(65,25);
    ui->toolButton_Undo_Script->setFixedSize(65,25);
    ui->toolButton_Generate_Desktop->setFixedSize(65,25);
    ui->toolButton_Undo_Desktop->setFixedSize(65,25);
    connect(ui->toolButton_2, SIGNAL(clicked()), this, SLOT(click_button_2()));
    connect(ui->toolButton_3, SIGNAL(clicked()), this, SLOT(click_button_3()));
    connect(ui->toolButton_4, SIGNAL(clicked()), this, SLOT(click_button_4()));
    connect(ui->toolButton_6, SIGNAL(clicked()), this, SLOT(click_button_6()));
    connect(ui->toolButton_7, SIGNAL(clicked()), this, SLOT(click_button_7()));
    connect(ui->toolButton_8, SIGNAL(clicked()), this, SLOT(click_button_8()));
    connect(ui->toolButton_9, SIGNAL(clicked()), this, SLOT(click_button_9()));
    connect(ui->toolButton_Generate_Xml, SIGNAL(clicked()), this, SLOT(click_button_Generate_Xml()));
    connect(ui->toolButton_Undo_Xml, SIGNAL(clicked()), this, SLOT(click_button_Undo_Xml()));
    connect(ui->toolButton_Generate_Script, SIGNAL(clicked()), this, SLOT(click_button_Generate_Script()));
    connect(ui->toolButton_Undo_Script, SIGNAL(clicked()), this, SLOT(click_button_Undo_Script()));
    connect(ui->toolButton_Generate_Desktop, SIGNAL(clicked()), this, SLOT(click_button_Generate_Desktop()));
    connect(ui->toolButton_Undo_Desktop, SIGNAL(clicked()), this, SLOT(click_button_Undo_Desktop()));


    //add mencius  ---->page_2
    QScrollBar* slider = new QScrollBar(Qt::Vertical, ui->scrollAreaWidgetContents_2);
    ui->scrollArea_2->setVerticalScrollBar(slider);
    QString vertical_text = QString("QScrollBar:vertical"
                                    "{"
                                    "width:8px;"
                                    "background:rgba(0,0,0,0%);"
                                    "margin:0px,0px,0px,0px;"
                                    "padding-top:9px;"
                                    "padding-bottom:9px;"
                                    "}"
                                    "QScrollBar::handle:vertical"
                                    "{"
                                    "width:8px;"
                                    "background:rgba(0,150,237,25%);"
                                    " border-radius:4px;"
                                    "min-height:20;"
                                    "}"
                                    "QScrollBar::handle:vertical:hover"
                                    "{"
                                    "width:8px;"
                                    "background:rgba(0,150,237,60%);"
                                    " border-radius:4px;"
                                    "min-height:20;"
                                    "}"
                                    "QScrollBar::add-line:vertical"
                                    "{"
                                    "height:9px;width:8px;"
                                   "border-image:url(/usr/share/cpktransform/images/down_normal.png);"
                                    "subcontrol-position:bottom;"
                                    "}"
                                    "QScrollBar::sub-line:vertical"
                                    "{"
                                    "height:9px;width:8px;"
                                    "border-image:url(/usr/share/cpktransform/images/up_normal.png);"
                                    "subcontrol-position:top;"
                                    "}"
                                    "QScrollBar::add-line:vertical:hover"
                                    "{"
                                    "height:9px;width:8px;"
                                    "border-image:url(/usr/share/cpktransform/images/down_pressed.png);"
                                    "subcontrol-position:bottom;"
                                    "}"
                                    "QScrollBar::sub-line:vertical:hover"
                                    "{"
                                    "height:9px;width:8px;"
                                    "border-image:url(/usr/share/cpktransform/images/up_pressed.png);"
                                    "subcontrol-position:top;"
                                    "}"
                                    "QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical"
                                    "{"
                                    "background:rgba(77,0,0,10%);"
                                    "border-radius:4px;"
                                    "}");
    ui->textEdit_help->verticalScrollBar()->setStyleSheet(vertical_text);
    ui->textEdit_help->setStyleSheet("border:0px;color:rgb(105,105,105);background-color:rgb(245,245,245);");
    ui->scrollArea_2->verticalScrollBar()->setStyleSheet(vertical_text);
    ui->scrollArea_2->verticalScrollBar()->setTracking(true);
  //  connect(ui->scrollArea_2->verticalScrollBar(),SIGNAL(valueChanged(int)),
   //         this, SLOT(scrollbar_value_changed(int)));
    ui->lineEdit_target->setFixedHeight(27);
    ui->lineEdit_target->setFixedWidth(410);


//2“安装脚本”
#if 0
    ui->lineEdit_script->setFixedHeight(27);
    ui->textEdit_script->setFixedHeight(445);
    ui->lineEdit_script->setPlaceholderText(" 格式为：软件名.install ");
    ui->textEdit_script->verticalScrollBar()->setStyleSheet(vertical_text);
    ui->textEdit_script->setText("#! /usr/bin/bash\n\
 \n\
#在Deb解包之前，将会运行该脚本\n\
pre_install()\n\
{\n\
    :\n\
} \n\
#负责完成安装包时的配置\n\
post_install()\n\
{\n\
    :\n\
} \n\
#负责停止与软件包相关联的daemon服务\n\
pre_remove()\n\
{\n\
    :\n\
} \n\
#负责修改软件包连接或文件关联\n\
post_remove()\n\
{\n\
    :\n\
} \n\
  ");
#else
    QGridLayout* gbox_script = new QGridLayout();
    QLabel* in =    new QLabel("脚本名称2：");
    in->setStyleSheet("QLabel{border-width:0px;}");
    QLabel* in_text = new QLabel("脚本内容：");
    in_text->setStyleSheet("QLabel{border-width:0px;}");
    script_line2 = new CLineEdit();
    script_edit2 = new QTextEdit();
    script_line2->setFixedHeight(27);
    //     script_line2->setFixedWidth(380);
    script_line2->setFixedWidth(340);
    script_line2->setPlaceholderText(" 格式为：软件名.install ");
    script_line2->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    script_edit2->setStyleSheet("QTextEdit{background:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    script_edit2->verticalScrollBar()->setStyleSheet(vertical_text);
    //     script_edit2->setFixedWidth(380);
    script_edit2->setFixedWidth(340);
    script_edit2->setText("#! /usr/bin/bash\n\
\n\
#在Deb解包之前，将会运行该脚本\n\
pre_install()\n\
{\n\
    :\n\
} \n\
#负责完成安装包时的配置\n\
post_install()\n\
{\n\
    :\n\
} \n\
#负责停止与软件包相关联的daemon服务\n\
pre_remove()\n\
{\n\
    :\n\
} \n\
#负责修改软件包连接或文件关联\n\
post_remove()\n\
{\n\
    :\n\
} \n\
pre_upgrade()\n\
{\n\
    :\n\
} \n\
post_upgrade()\n\
{\n\
    :\n\
} \n\
pre_downgrade()\n\
{\n\
     :\n\
} \n\
post_upgrade()\n\
{\n\
    :\n\
} \n\
");
    gbox_script->addWidget(in, 0,0,1,1);
    gbox_script->addWidget(script_line2, 0,1,1,1);
    gbox_script->addWidget(in_text,1,0,1,1);
    gbox_script->addWidget(script_edit2,1,1,1,1);
    gbox_script->setAlignment(in_text, Qt::AlignTop);
    gbox_script->setAlignment(script_line2,Qt::AlignLeft);
    gbox_script->setAlignment(script_edit2,Qt::AlignLeft);

    ui->widget_5->setLayout(gbox_script);
    ui->widget_5->setStyleSheet("color:rgb(105,105,105);border:1px solid #E5E5E5;border-radius:1px;background-color:rgb(245,245,245)");//mencius
    ui->widget_5->setAutoFillBackground(true);
#endif

//     1“基本信息”

    control_xml_1= new Xml(ui->gridLayout_info);
    QToolButton *tExec = new QToolButton();
    tExec->setFixedSize(130,27);
    tExec->setStyleSheet(strQToolButton);
    tExec->setText("选择执行程序路径");
    tExec->setCursor(Qt::PointingHandCursor);
    QHBoxLayout* hExec = new QHBoxLayout();
    hExec->addWidget(control_xml_1->lExec);
    hExec->addWidget(tExec);
    hExec->setAlignment(tExec, Qt::AlignLeft);
    control_xml_1->gbox_info->addLayout(hExec,7,1,1,1);

    //选择icon按钮
    QToolButton* tIcon = new QToolButton();
    tIcon->setFixedSize(130,27);
    tIcon->setStyleSheet(strQToolButton);
    tIcon->setText("选择图标");
    tIcon->setCursor(Qt::PointingHandCursor);
    connect( tIcon, SIGNAL(clicked()), this, SLOT(click_btn_icon()));

    //    gbox_details->addWidget(tldesc_en,3,1,1,1);
//    QToolButton* tPic1 = new QToolButton();
//    tPic1->setFixedSize(130,27);
//    tPic1->setStyleSheet(strQToolButton);
//    tPic1->setText("添加截图");
//    tPic1->setCursor(Qt::PointingHandCursor);
//    connect( tPic1, SIGNAL(clicked()), this, SLOT(click_btn_pic()));

    QHBoxLayout* hIcon = new QHBoxLayout();
    hIcon->addWidget(control_xml_1->icon_le);
    hIcon->addWidget(tIcon);
//    hIcon->addWidget(tPic1);
    hIcon->setAlignment(tIcon, Qt::AlignLeft);
    control_xml_1->gbox_info->addLayout(hIcon,8,1,1,1);

    QLabel* s_hp = new QLabel("软件主页：");
    l_hp = new QLineEdit();
    s_hp->setStyleSheet("QLabel{border-width:0px;}");
    l_hp->setStyleSheet("QLineEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    l_hp->setFixedSize(200,27);
    control_xml_1->gbox_other->addWidget(s_hp, 4,0,1,1);
    control_xml_1->gbox_other->addWidget(l_hp,4,1,1,1);
    control_xml_1->s_other->setFixedSize(470,180);
    connect( control_xml_1->sProtocol, SIGNAL(currentIndexChanged(int)), this, SLOT(process_Protocol(int)));
    connect( control_xml_1->grp1, SIGNAL(buttonClicked (int)), this, SLOT(button_desktop_Judge(int)));
    connect( control_xml_1->grp2, SIGNAL(buttonClicked (int)), this, SLOT(button_patch_Judge(int)));
    connect( control_xml_1->grp3, SIGNAL(buttonClicked (int)), this, SLOT(button_essential_Judge(int)));
    connect( tExec, SIGNAL(clicked()), this, SLOT(click_btn_exec()));

    ui->lineEdit_type->setText("Application");
    ui->lineEdit_terminal->setText("true");
    ui->lineEdit_hidden->setText("true");
//    ui->lineEdit_category->setText("AudioVideo");
    ui->lineEdit_category->setText("");
    ui->lineEdit_name->setFixedSize(200,27);
    ui->lineEdit_genericname->setFixedSize(200,27);
    ui->lineEdit_comment->setFixedSize(200,27);
    ui->lineEdit_type->setFixedSize(200,27);
    ui->lineEdit_icon->setFixedSize(200,27);
    ui->lineEdit_version->setFixedSize(200,27);
    ui->lineEdit_terminal->setFixedSize(200,27);
    ui->lineEdit_hidden->setFixedSize(200,27);
    ui->lineEdit_category->setFixedSize(200,27);
    ui->lineEdit_category->setPlaceholderText("类别以英文分号隔开");
    ui->lineEdit_exec->setFixedSize(200,27);
//    ui->comboBox_category->setFixedWidth(120);
//    ui->comboBox_hidden->setFixedWidth(120);
    ui->comboBox_category->setEnabled(false);
    ui->comboBox_category->hide();
    ui->comboBox_terminal->setFixedWidth(120);
    ui->comboBox_type->setFixedWidth(120);

    connect(ui->comboBox_type, SIGNAL(currentIndexChanged(int)), this, SLOT(process_type_get(int)));
    connect(ui->comboBox_terminal, SIGNAL(currentIndexChanged(int)), this, SLOT(process_terminal_get(int)));
    connect(ui->comboBox_hidden, SIGNAL(currentIndexChanged(int)), this, SLOT(process_hidden_get(int)));
//    connect(ui->comboBox_category, SIGNAL(currentIndexChanged(int)), this, SLOT(process_category_get(int)));

    ui->textEdit_help->setFixedSize(535,510);
    ui->textEdit_help->setReadOnly(true);

    QTextCodec * code = QTextCodec::codecForName("utf8");
    QFile file("/usr/share/cpktransform/usermanual_package.txt");
    if ( !file.open(QIODevice::ReadOnly | QIODevice::Text) )
        return ;

    QTextStream stream(&file);
    stream.setCodec(code);//对输出流的设置
    while (stream.atEnd() == 0)
    {
        ui->textEdit_help->setText(stream.readAll());
    }

    ui->label_8->setFixedWidth(70);
    //进入界面时，滚动条不滚动
    this->progreddBarEnable(false);
}

void MainWindow::createUI_page_error()
{

}

void MainWindow::process_type_get(int id)
{
    switch(id)
    {
    case 0:
    {
        ui->lineEdit_type->setText("Application");
        break;
    }
    case 1:
    {
        ui->lineEdit_type->setText("Link");
        break;
    }
    default:
        break;
    }
}

void MainWindow::process_terminal_get(int id)
{
    switch(id)
    {
    case 0:
    {
        ui->lineEdit_terminal->setText("true");
        break;
    }
    case 1:
    {
        ui->lineEdit_terminal->setText("false");
        break;
    }
    default:
        break;
    }
}

void MainWindow::process_hidden_get(int id)
{
    switch(id)
    {
    case 0:
    {
        ui->lineEdit_hidden->setText("true");
        break;
    }
    case 1:
    {
        ui->lineEdit_hidden->setText("false");
        break;
    }
    default:
        break;
    }
}

void MainWindow::process_category_get(int id)
{
    switch(id)
    {
    case 0:
    {
        ui->lineEdit_category->setText("AudioVideo");
        break;
    }
    case 1:
    {
        ui->lineEdit_category->setText("Audio");
        break;
    }
    case 2:
    {
        ui->lineEdit_category->setText("Video");
        break;
    }
    case 3:
    {
        ui->lineEdit_category->setText("Development");
        break;
    }
    case 4:
    {
        ui->lineEdit_category->setText("Education");
        break;
    }
    case 5:
    {
        ui->lineEdit_category->setText("Game");
        break;
    }
    case 6:
    {
        ui->lineEdit_category->setText("Graphics");
        break;
    }
    case 7:
    {
        ui->lineEdit_category->setText("Network");
        break;
    }
    case 8:
    {
        ui->lineEdit_category->setText("Office");
        break;
    }
    case 9:
    {
        ui->lineEdit_category->setText("Science");
        break;
    }
    case 10:
    {
        ui->lineEdit_category->setText("Settings");
        break;
    }
    case 11:
    {
        ui->lineEdit_category->setText("System");
        break;
    }
    case 12:
    {
        ui->lineEdit_category->setText("Utility");
        break;
    }
    default:
        break;
    }
}

void MainWindow::click_button()
{
    occupying_dig->setVisible(true);
    dig1->setVisible(false);
    dig2->setVisible(false);
    dig3->setVisible(false);
    dig4->setVisible(false);
    dig5->setVisible(false);
    dig6->setVisible(false);
    ui->stackedWidget_3->setCurrentIndex(1);
}

void MainWindow::click_button_icon()
{
    dig1->setVisible(true);
    dig2->setVisible(true);
    dig3->setVisible(true);
    dig4->setVisible(true);
    dig5->setVisible(true);
    dig6->setVisible(true);
    ui->stackedWidget_3->setCurrentIndex(0);
}

void MainWindow::click_button_2()
{
    ui->label_tip_xml->clear();
    ui->stackedWidget_2->setCurrentIndex(1);
    ui->toolButton_2->setStyleSheet("QToolButton {\
                                    color:rgb(105,105,105);\
                                    background-color:rgb(245,245,245);\
                                     border: 0px solid #8f8f91;\
                                     border-radius: 0px;\
                                 }");
    ui->toolButton_2->setFixedSize(156,40);
    ui->toolButton_3->setStyleSheet(strQToolButton2);
    ui->toolButton_4->setStyleSheet(strQToolButton2);
    ui->toolButton_9->setStyleSheet(strQToolButton2);
}

void MainWindow::click_button_3()
{
    ui->label_tip_install->clear();
    ui->stackedWidget_2->setCurrentIndex(2);
    ui->toolButton_3->setStyleSheet("QToolButton {\
                                    color:rgb(105,105,105);\
                                    background-color:rgb(245,245,245);\
                                     border: 0px solid #8f8f91;\
                                     border-radius: 0px;\
                                 }");
    ui->toolButton_3->setFixedSize(156,40);
    ui->toolButton_2->setStyleSheet(strQToolButton2);
    ui->toolButton_4->setStyleSheet(strQToolButton2);
    ui->toolButton_9->setStyleSheet(strQToolButton2);
}

void MainWindow::click_button_4()
{
    ui->label_tip_desktop->clear();
    ui->stackedWidget_2->setCurrentIndex(3);
    ui->toolButton_4->setStyleSheet("QToolButton {\
                                    color:rgb(105,105,105);\
                                    background-color:rgb(245,245,245);\
                                     border: 0px solid #8f8f91;\
                                     border-radius: 0px;\
                                 }");
    ui->toolButton_4->setFixedSize(156,40);
    ui->toolButton_2->setStyleSheet(strQToolButton2);
    ui->toolButton_3->setStyleSheet(strQToolButton2);
    ui->toolButton_9->setStyleSheet(strQToolButton2);
}

void MainWindow::click_button_6()
{
    //选择目标路径
    QString dir = QFileDialog::getExistingDirectory(this, "选择目标目录", "/home", QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly | QFileDialog::DontUseNativeDialog);
    if(!dir.isEmpty())
    {
        ui->lineEdit_target->setText(dir);
        str_Target = ui->lineEdit_target->text();
    }

}

//存在路径层级问题
////desktob
//void MainWindow::click_button_7()
//{
//    QFileDialog* openFilePath = new QFileDialog(this);
//    openFilePath->setWindowTitle("请选择图标文件");
//    openFilePath->setDirectory(str_Source + "/usr/share/icons/hicolor");
//#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
//    openFilePath->setFilter(tr("Image Files(*.jpg *.png *.xpm)"));
//#endif
//    QStringList strList;
//    if(openFilePath->exec() == QDialog::Accepted)
//    {
//        strList = openFilePath->selectedFiles()[0].split("/");
//        int nCount  = strList.size();
//        QString spath = "/";
//        QString strPath = spath +strList.at(nCount - 7) +"/"+ strList.at(nCount - 6)+"/"+strList.at(nCount - 5)+"/"+strList.at(nCount - 4)+"/"+strList.at(nCount - 3)+"/"
//                +strList.at(nCount - 2)+"/"+strList.at(nCount - 1);
//        ui->lineEdit_icon->setText(strPath);
//    }
//    delete openFilePath;
//}

//desktob
void MainWindow::click_button_7()
{
    QFileDialog* openFilePath = new QFileDialog(this);
    openFilePath->setWindowTitle("请选择图标文件");
    openFilePath->setDirectory(str_Source);
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
    openFilePath->setFilter(tr("Image Files(*.jpg *.png *.xpm)"));
#endif
    QString pic_file_path;
    if(openFilePath->exec() == QDialog::Accepted)
    {
        pic_file_path = openFilePath->selectedFiles()[0];

        if( pic_file_path.mid(0,str_Source.length()) == str_Source )
        {
            pic_file_path = pic_file_path.mid(str_Source.length());
        }

        ui->lineEdit_icon->setText(pic_file_path);

    }
    delete openFilePath;
}

//打包页page_4,打包按钮响应事件
void MainWindow::click_button_8()
{
    ui->progressBar_3->setFormat("");
    bool bXMl = false;
    //    bool bDesktop = false;
    bool bInstall = false;
    ui->toolButton_8->setFixedSize(80,27);
    if(!str_Source.isEmpty() && !ui->lineEdit_target->text().isEmpty())
    {
        //        此处生成不合适，其他文件都具备时再生成
        //        //首先生成filelist文件
        //        cpkfilelistgeneration();
        //检测CPK文件夹中相关文件是否已经存在
        QString strCPK = str_Source+"/CPK/";
        QFileInfoList list = QDir(strCPK).entryInfoList();
#if 0
        for(int i = 0; i < list.size(); ++i){
            QFileInfo fileInfo = list.at(i);
            QString name = fileInfo.fileName();
            QStringList strList = name.split(".");
            if(strList.size() == 2 && !strcmp(strList.at(1).toLocal8Bit().data(),"desktop"))
                bDesktop = true;
        }
        if(bDesktop == false)
            ui->progressBar_3->setFormat("菜单启动器文件没有生成！");
#endif
        for(int i = 0; i < list.size(); ++i){
            QFileInfo fileInfo = list.at(i);
            QString name = fileInfo.fileName();
            QStringList strList = name.split(".");
            if(strList.size() == 2 && !strcmp(strList.at(1).toLocal8Bit().data(),"install"))
                bInstall = true;
        }
        if(bInstall == false)
            ui->progressBar_3->setFormat("安装脚本文件没有生成！");
        for(int i = 0; i < list.size(); ++i){
            QFileInfo fileInfo = list.at(i);
            QString name = fileInfo.fileName();
            if(!strcmp(name.toLocal8Bit().data(), "control.xml"))
                bXMl = true;
        }
        if(bXMl == false)
            ui->progressBar_3->setFormat("control.xml文件没有生成！");

        if(bXMl && bInstall)
        {
            ui->progressBar_3->setVisible(true);
            timer3 = new QTimer(this);
            connect(timer3,SIGNAL(timeout()),this,SLOT(timeUpDate3()));
            timer3->start(200);
            ui->progressBar_3->setFormat("正在打包中...");

            //            生成filelist文件
            //            cpkfilelistgeneration();
            Thread* thread_py = new Thread(bFlag_type,str_Source, cache_dir, py_filelist);
            thread_py->start();
            connect(thread_py, SIGNAL(signal_Msg_py_end(int)), this, SLOT(slot_Msg_py_end(int)));
            connect(thread_py, SIGNAL(signal_Msg_error(QString)), this, SLOT(slot_Msg_pack_end(QString)));

            //这部分代码置于slot_Msg_py_end(int thread_type)中
            //            //打包
            //            //拼接新的包路径和名称
            //            QString dist_name = ui->lineEdit_target->text() +"/"+control_xml_1->sname_en->text()+"_"+control_xml_1->l_1->text()+"."+control_xml_1->l_2->text()+"."+control_xml_1->l_3->text() +"_"+ control_xml_1->larch->text()+".cpk";
            //            QString Command = QString("cpkg --pack %1  %2").arg(str_Source).arg(dist_name);
            //            thread_package2 = new Thread(Command);
            //            thread_package2->cache_dir = cache_dir;
            //            connect(thread_package2, SIGNAL(signal_Msg_pack_end(QString)),
            //                         this, SLOT(slot_Msg_pack_end(QString)));
            //            connect(thread_package2, SIGNAL(signal_Msg_error(QString)), this, SLOT(slot_Msg_pack_end(QString)));
            //            thread_package2->start();
        }
    }
}

void MainWindow::click_button_9()
{
    ui->stackedWidget_2->setCurrentIndex(4);
    ui->toolButton_9->setStyleSheet("QToolButton {\
                                    color:rgb(105,105,105);\
                                    background-color:rgb(245,245,245);\
                                     border: 0px solid #8f8f91;\
                                     border-radius: 0px;\
                                 }");
    ui->toolButton_9->setFixedSize(156,40);
    ui->toolButton_2->setStyleSheet(strQToolButton2);
    ui->toolButton_3->setStyleSheet(strQToolButton2);
    ui->toolButton_4->setStyleSheet(strQToolButton2);
}

void MainWindow::click_button_Generate_Xml()
{
    if(control_xml_1 && !str_Source.isEmpty())
    {
        if(control_xml_1->sname_en->text().isEmpty())
            control_xml_1->sname_en->m_timer.start();
        else
        {
            if( control_xml_1->sname->text().isEmpty() )
                control_xml_1->sname->m_timer.start();
            else
            {
                if(control_xml_1->l_1->text().isEmpty() )
                    control_xml_1->l_1->m_timer.start();
                else
                {
                    if(control_xml_1->l_2->text().isEmpty() )
                        control_xml_1->l_2->m_timer.start();
                    else
                    {
                        if(control_xml_1->l_3->text().isEmpty()  )
                            control_xml_1->l_3->m_timer.start();
                        else
                        {
                            if( control_xml_1->larch->text().isEmpty() )
                                control_xml_1->larch->m_timer.start();
                            else
                            {
                                if(control_xml_1->lExec->text().isEmpty())
                                    control_xml_1->lExec->m_timer.start();
                            }
                        }
                    }
                }
            }
        }

        if(!control_xml_1->sname_en->text().isEmpty() &&
                !control_xml_1->sname->text().isEmpty() &&
                !control_xml_1->l_1->text().isEmpty() &&
                !control_xml_1->l_2->text().isEmpty() &&
                !control_xml_1->l_3->text().isEmpty()  &&
                !control_xml_1->larch->text().isEmpty() &&
                !control_xml_1->lExec->text().isEmpty())
        {
            control_xml_1->str_soft_hp = l_hp->text();
            control_xml_1->create_xml(str_Source);
            ui->label_tip_xml->setText("control.xml文件已生成！");
            if(!control_xml_1->sname_en->text().isEmpty())
            {
                script_line2->setText(control_xml_1->sname_en->text()+".install");
                ui->lineEdit_name->setText(control_xml_1->sname_en->text());
            }
            if(!control_xml_1->sname->text().isEmpty())
                ui->lineEdit_genericname->setText(control_xml_1->sname->text());
            if(!control_xml_1->l_1->text().isEmpty() && !control_xml_1->l_2->text().isEmpty() && !control_xml_1->l_3->text().isEmpty())
                ui->lineEdit_version->setText(control_xml_1->l_1->text()+"."+control_xml_1->l_2->text()+"."+control_xml_1->l_3->text());
            if(!control_xml_1->lExec->text().isEmpty())
                ui->lineEdit_exec->setText(control_xml_1->lExec->text());

            //重置图标/截图文件名称
            reset_iconFileName();
            reset_screenshotFileName();
        }
    }
    else
    {
        ui->label_tip_xml->setText("路径设置不能为空！");
    }
}

void MainWindow::click_button_Undo_Xml()
{
    if(control_xml_1)
    {
        control_xml_1->delete_data();
        l_hp->clear();
    }
}

void MainWindow::click_button_Generate_Script()
{
    if(str_Source.isEmpty())
        ui->label_tip_install->setText("路径设置不能为空！");
    else
    {
        if( !script_line2->text().isEmpty())
        {
            //预先生成CPK文件夹Mencius
            QString cpk_path = str_Source  +"/CPK";
            QFileInfo fi(cpk_path.toLocal8Bit().data());
            if(fi.exists())
            {
                qDebug("存在CPK文件夹!（生成安装脚本）\n");
                //return -1;
            }
            else
            {
                //创建文件夹
                if(mkdir(cpk_path.toLocal8Bit().data(), 00700) < 0)
                {
                    printf("mkdir CPK error!1\n");
                    //                       exit(1);
                    emit signal_Msg_error("mkdir CPK error!1\n");
                    return;
                }
            }
            QString fname = str_Source + "/CPK/" + script_line2->text();//TODO
            //检测脚本文件是否存在
            QString strCPK = str_Source+"/CPK/";
            QFileInfoList list = QDir(strCPK).entryInfoList();
            for(int i = 0; i < list.size(); ++i){
                QFileInfo fileInfo = list.at(i);
                QString name = fileInfo.fileName();
                QStringList strList = name.split(".");
                if(strList.size() == 2 && !strcmp(strList.at(1).toLocal8Bit().data(),"install"))
                {
                    QString path = fileInfo.filePath();
                    QString delete_script = QString("rm %1").arg(path);
                    system(delete_script.toLocal8Bit().data());
                }
            }
            QFile file(fname);
            file.open(QIODevice::ReadWrite);
            QTextStream in(&file);
            in<<script_edit2->toPlainText()<<"\n";
            file.close();
            ui->label_tip_install->setText("安装脚本已生成！");
        }
        else
        {
            script_line2->m_timer.start();
            //ui->label_tip_install->setText("脚本名称不能为空！");
        }
    }
}

//生成desktop文件
int MainWindow::click_button_Generate_Desktop()
{
    if(!str_Source.isEmpty())
    {
        //预先生成CPK文件夹
        QString cpk_path = str_Source  +"/CPK";
        QFileInfo fi(cpk_path.toLocal8Bit().data());
        if(fi.exists())
        {
            qDebug("存在CPK文件夹!（生成菜单启动器文件）\n");
            //return -1;
        }
        else
        {
            //创建文件夹
            if(mkdir(cpk_path.toLocal8Bit().data(), 00700) < 0)
            {
                //              printf("mkdir CPK error!2\n");
                //              exit(1);
                emit signal_Msg_error("mkdir CPK error!2\n");
                return -1;
            }
        }
        if(control_xml_1 && !control_xml_1->sname_en->text().isEmpty())
        {
            QString filename = cpk_path + "/"+control_xml_1->sname_en->text()+".desktop";//TODO
            //检测脚本文件是否存在
            QFileInfoList list = QDir(cpk_path).entryInfoList();
            for(int i = 0; i < list.size(); ++i){
                QFileInfo fileInfo = list.at(i);
                QString name = fileInfo.fileName();
                QStringList strList = name.split(".");
                if(strList.size() == 2 && !strcmp(strList.at(1).toLocal8Bit().data(),"desktop"))
                {
                    QString path = fileInfo.filePath();
                    QString delete_desktop = QString("rm %1").arg(path);
                    system(delete_desktop.toLocal8Bit().data());
                }
            }
            QFile f(filename);
            if(!f.open(QIODevice::WriteOnly | QIODevice::Text))
            {
                qDebug("Open failed.");
                //return -1;
                emit signal_Msg_error("Open failed.");
                return -1;
            }
            QTextStream txtOutput(&f);
            QString s1("[Desktop Entry]");
            QString s2("Name=");
            QString s3("GenericName=");
            QString s4("Comment=");
            QString s5("Type=");
            QString s6("Icon=");
            QString s7("Version=");
            QString s8("Exec=");
            QString s9("Terminal=");
            QString s10("Hidden=");
            QString s11("Categories=");
            txtOutput << s1 << endl;
            txtOutput << s2 << ui->lineEdit_name->text()<<endl;
            txtOutput << s3 << ui->lineEdit_genericname->text()<< endl;
            txtOutput << s4 << ui->lineEdit_comment->text()<< endl;
            txtOutput << s5 << ui->lineEdit_type->text()<<endl;
            txtOutput << s6 << ui->lineEdit_icon->text()<<endl;
            txtOutput << s7 << ui->lineEdit_version->text()<<endl;
            txtOutput << s8 << ui->lineEdit_exec->text()<<endl;
            txtOutput << s9 << ui->lineEdit_terminal->text()<<endl;
            txtOutput << s10 << ui->lineEdit_hidden->text()<<endl;
            txtOutput << s11 << ui->lineEdit_category->text()<<endl;
            f.close();
            ui->label_tip_desktop->setText("菜单启动器文件已生成！");
        }
        else
            ui->label_tip_desktop->setText("基本信息里的软件名称不能为空！");
    }
    else
        ui->label_tip_desktop->setText("路径设置不能为空！");
    return 0;
}

void MainWindow::click_button_Undo_Desktop()
{
     ui->lineEdit_name->clear();
     ui->lineEdit_genericname->clear();
     ui->lineEdit_comment->setText("");
     ui->lineEdit_type->setText("Application");
     ui->comboBox_type->setCurrentIndex(0);
     ui->lineEdit_icon->clear();
     ui->lineEdit_version->clear();
     ui->lineEdit_exec->clear();
     ui->comboBox_terminal->setCurrentIndex(0);
     ui->comboBox_hidden->setCurrentIndex(0);
     ui->lineEdit_hidden->setText("true");
     ui->lineEdit_terminal->setText("true");
//     ui->lineEdit_category->setText("AudioVideo");
     ui->lineEdit_category->setText("");
//     ui->comboBox_category->setCurrentIndex(0);
}


void MainWindow::set_scrollbar_value_by_dig1()
{
    ui->scrollArea->verticalScrollBar()->setValue(10);
    QPixmap p_dig;
    p_dig.load("/usr/share/cpktransform/images/2_normal.png");
    dig2->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/3_normal.png");
    dig3->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/4_normal.png");
    dig4->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/5_normal.png");
    dig5->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/6_normal.png");
    dig6->setIcon(p_dig);
    dig2->is_release = false;
    dig3->is_release = false;
    dig4->is_release = false;
    dig5->is_release = false;
    dig6->is_release = false;
}

void MainWindow::set_scrollbar_value_by_dig2()
{
    ui->scrollArea->verticalScrollBar()->setValue(320);
    QPixmap p_dig;
    p_dig.load("/usr/share/cpktransform/images/1_normal.png");
    dig1->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/3_normal.png");
    dig3->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/4_normal.png");
    dig4->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/5_normal.png");
    dig5->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/6_normal.png");
    dig6->setIcon(p_dig);
    dig1->is_release = false;
    dig3->is_release = false;
    dig4->is_release = false;
    dig5->is_release = false;
    dig6->is_release = false;
}

void MainWindow::set_scrollbar_value_by_dig3()
{
    ui->scrollArea->verticalScrollBar()->setValue(610);
    QPixmap p_dig;
    p_dig.load("/usr/share/cpktransform/images/2_normal.png");
    dig2->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/1_normal.png");
    dig1->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/4_normal.png");
    dig4->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/5_normal.png");
    dig5->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/6_normal.png");
    dig6->setIcon(p_dig);
    dig2->is_release = false;
    dig1->is_release = false;
    dig4->is_release = false;
    dig5->is_release = false;
    dig6->is_release = false;
}

void MainWindow::set_scrollbar_value_by_dig4()
{
    ui->scrollArea->verticalScrollBar()->setValue(1040);
    QPixmap p_dig;
    p_dig.load("/usr/share/cpktransform/images/2_normal.png");
    dig2->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/3_normal.png");
    dig3->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/1_normal.png");
    dig1->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/5_normal.png");
    dig5->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/6_normal.png");
    dig6->setIcon(p_dig);
    dig3->is_release = false;
    dig2->is_release = false;
    dig1->is_release = false;
    dig5->is_release = false;
    dig6->is_release = false;
}

void MainWindow::set_scrollbar_value_by_dig5()
{
    ui->scrollArea->verticalScrollBar()->setValue(1320);
    QPixmap p_dig;
    p_dig.load("/usr/share/cpktransform/images/1_normal.png");
    dig1->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/2_normal.png");
    dig2->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/3_normal.png");
    dig3->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/4_normal.png");
    dig4->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/6_normal.png");
    dig6->setIcon(p_dig);
    dig4->is_release = false;
    dig3->is_release = false;
    dig2->is_release = false;
    dig1->is_release = false;
    dig6->is_release = false;
}

void MainWindow::set_scrollbar_value_by_dig6()
{
    ui->scrollArea->verticalScrollBar()->setValue(1500);
    QPixmap p_dig;
    p_dig.load("/usr/share/cpktransform/images/1_normal.png");
    dig1->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/2_normal.png");
    dig2->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/3_normal.png");
    dig3->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/4_normal.png");
    dig4->setIcon(p_dig);
    p_dig.load("/usr/share/cpktransform/images/5_normal.png");
    dig5->setIcon(p_dig);
    dig2->is_release = false;
    dig3->is_release = false;
    dig4->is_release = false;
    dig1->is_release = false;
    dig5->is_release = false;
}


void MainWindow::scrollbar_value_changed(int value)
{
    if(value <=320)
    {
        QPixmap p_dig;
        p_dig.load("/usr/share/cpktransform/images/2_normal.png");
        dig2->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/3_normal.png");
        dig3->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/4_normal.png");
        dig4->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/5_normal.png");
        dig5->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/6_normal.png");
        dig6->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/1_sel.png");
        dig1->setIcon(p_dig);
        dig1->is_release = true;
        dig2->is_release = false;
        dig3->is_release = false;
        dig4->is_release = false;
        dig5->is_release = false;
        dig6->is_release = false;
    }
    else if (value <= 610 && value >320)
    {
        QPixmap p_dig;
        p_dig.load("/usr/share/cpktransform/images/1_normal.png");
        dig1->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/3_normal.png");
        dig3->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/4_normal.png");
        dig4->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/5_normal.png");
        dig5->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/6_normal.png");
        dig6->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/2_sel.png");
        dig2->setIcon(p_dig);
        dig2->is_release = true;
        dig1->is_release = false;
        dig3->is_release = false;
        dig4->is_release = false;
        dig5->is_release = false;
        dig6->is_release = false;
    }
    else if(value<= 1040&& value > 610)
    {
        QPixmap p_dig;
        p_dig.load("/usr/share/cpktransform/images/2_normal.png");
        dig2->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/1_normal.png");
        dig1->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/4_normal.png");
        dig4->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/5_normal.png");
        dig5->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/6_normal.png");
        dig6->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/3_sel.png");
        dig3->setIcon(p_dig);
        dig3->is_release = true;
        dig2->is_release = false;
        dig1->is_release = false;
        dig4->is_release = false;
        dig5->is_release = false;
        dig6->is_release = false;
    }
    else if(value <=1320&& value >1040)
    {
        QPixmap p_dig;
        p_dig.load("/usr/share/cpktransform/images/2_normal.png");
        dig2->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/3_normal.png");
        dig3->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/1_normal.png");
        dig1->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/5_normal.png");
        dig5->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/6_normal.png");
        dig6->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/4_sel.png");
        dig4->setIcon(p_dig);
        dig4->is_release = true;
        dig3->is_release = false;
        dig2->is_release = false;
        dig1->is_release = false;
        dig5->is_release = false;
        dig6->is_release = false;
    }
    else if(value > 1320 && value <= 1500)
    {
        QPixmap p_dig;
        p_dig.load("/usr/share/cpktransform/images/1_normal.png");
        dig1->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/2_normal.png");
        dig2->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/3_normal.png");
        dig3->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/4_normal.png");
        dig4->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/6_normal.png");
        dig6->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/5_sel.png");
        dig5->setIcon(p_dig);
        dig5->is_release = true;
        dig4->is_release = false;
        dig3->is_release = false;
        dig2->is_release = false;
        dig1->is_release = false;
        dig6->is_release = false;
    }
    else if(value > 1500)
    {
        QPixmap p_dig;
        p_dig.load("/usr/share/cpktransform/images/2_normal.png");
        dig2->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/3_normal.png");
        dig3->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/4_normal.png");
        dig4->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/1_normal.png");
        dig1->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/5_normal.png");
        dig5->setIcon(p_dig);
        p_dig.load("/usr/share/cpktransform/images/6_sel.png");
        dig6->setIcon(p_dig);
        dig6->is_release = true;
        dig4->is_release = false;
        dig3->is_release = false;
        dig2->is_release = false;
        dig1->is_release = false;
        dig5->is_release = false;
    }
}

void MainWindow::click_btn_package_button()
{
    ui->stackedWidget->setCurrentIndex(5);
    bFlag_type = 1;
}

void MainWindow::click_btn_transfer_button()
{
    QPixmap p_title2;
    p_title2.load("/usr/share/cpktransform/images/title_1.png");
    QPalette   palette_title2;
    palette_title2.setBrush(t->backgroundRole(),QBrush(p_title2));
    t->setPalette(palette_title2);
    t->setFixedWidth(p_title2.width());
    t->setFixedHeight(p_title2.height());
    ui->stackedWidget->setCurrentIndex(1);
    bFlag_type = 2;
    btn_transfer->is_release = false;

    this->progreddBarEnable(false);
}

void MainWindow::click_btnbutton()
{
    timer->start(25);
    ui->progressBar->setFormat("正在解压包...");
    this->progreddBarEnable(true);
    btn->setEnabled(false);
    btn->is_release = true;
    tlb->is_release = false;
    //解压
    if(!debfile_path.isEmpty())
    {
        thread_extract = new Thread(debfile_path,   soft_name,  runPath);
        connect(thread_extract, SIGNAL(signal_Msg_extract_end()),
                this, SLOT(slot_Msg_extract_end()));
        connect(thread_extract, SIGNAL(signal_Msg_error(QString)), this, SLOT(slot_Msg_error(QString)));
        thread_extract->start();
    }
}

void MainWindow::click_tlbbutton()
{
    //    this->progreddBarEnable(true);
    tlb->is_release = true;
    btn->is_release = false;
    // To pop up this page after clicking
    openFilePath = new QFileDialog(this);
    openFilePath->setWindowTitle("请选择文件");
    openFilePath->setDirectory(".");
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
    openFilePath->setFilter(tr("select package (*.deb *.rpm)"));
#endif
    QStringList strList;
    if(openFilePath->exec() == QDialog::Accepted)
    {
#if 0
        debfile_path = openFilePath->selectedFiles()[0];
        deb_path = openFilePath->selectedFiles()[0];
        strList = debfile_path.split(".deb");
        extract_path = strList.at(0).toLocal8Bit().data();
        strList = extract_path.split("/");
        int nCount = strList.size();
        debfile_path.clear();
        for(int i=0;i<nCount -1;++i)
        {
            debfile_path = debfile_path + strList.at(i).toLocal8Bit().data() +"/";
        }
        soft_name = strList.at(nCount -1) + ".deb" ;
        btn->setEnabled(true);
    }
    tlb->is_release = false;
    delete openFilePath;
#else
        debfile_path = openFilePath->selectedFiles()[0];
        deb_path = openFilePath->selectedFiles()[0];
        strList = debfile_path.split("/");
        int nCount = strList.size();
        soft_name = strList.at(nCount - 1).toLocal8Bit().data();
        debfile_path.clear();
        for(int i=0;i<nCount -1;++i)
        {
            debfile_path = debfile_path + strList.at(i).toLocal8Bit().data() +"/";
        }
        btn->setEnabled(true);
    }
    tlb->is_release = false;
    delete openFilePath;
#endif
}

//page_10 打包-选择文件夹按钮 响应事件
void MainWindow::click_tlb2button()
{
    this->progreddBarEnable(true);
    //选择源文件路径
    QString dir = QFileDialog::getExistingDirectory(this, "选择源文件目录", "/home", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::DontUseNativeDialog);
    if(!dir.isEmpty())
    {
        str_Source = dir;
        delete_data();
        //如果CPK包里已经具有相关文件，那么从这些文件中读取数据到界面中
        if( read_fileinfo_to_ui() == 0)
        {
            QPixmap p_title2;
            p_title2.load("/usr/share/cpktransform/images/title_2.png");
            QPalette   palette_title2;
            palette_title2.setBrush(t->backgroundRole(),QBrush(p_title2));
            t->setPalette(palette_title2);
            t->setFixedWidth(p_title2.width());
            t->setFixedHeight(p_title2.height());
            ui->stackedWidget->setCurrentIndex(4);

            //读取截图数据
            screenshotmodel_loadData();
            //读取icon
            icon_loadData();
            //不读取desktop
//            desktop_loadData();

            //菜单关联
            static int i = 0;
            if( i++ );
            else{
//                connect(control_xml_1->tv_screenshot->horizontalHeader(),SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(slot_screenshot_menu_show(QPoint)));
                connect(control_xml_1->tv_screenshot,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(slot_screenshot_menu_show(QPoint)));
                connect(control_xml_1->screendshot_menu_edit_action,SIGNAL(triggered(bool)),this,SLOT(slot_screenshot_menu_edit()));
                connect(control_xml_1->screendshot_menu_del_action,SIGNAL(triggered(bool)),this,SLOT(slot_screenshot_menu_del()));

//                connect(control_xml_1->tv_screenshot,SIGNAL(clicked(QModelIndex)),this,SLOT(slot_screenshot_clicked(QModelIndex)));
                //提示
                connect(control_xml_1->tv_screenshot,SIGNAL(entered(QModelIndex)),this,SLOT(slot_screenshot_menu_row_detail(QModelIndex)));

            }
        }

    }
    tlb2->is_release = false;
}

void MainWindow::click_previousbutton()
{
    btn_package->is_release = false;
    btn_transfer->is_release = false;
    ui->stackedWidget->setCurrentIndex(0);
}

//”选择执行程序路径“按钮响应槽
//原版
//void MainWindow::click_btn_exec()
//{
//    QFileDialog* openFilePath = new QFileDialog(this);
//    openFilePath->setWindowTitle("选择软件执行程序");
//    if(bFlag_type == 1)
//        openFilePath->setDirectory(str_Source +"/usr/bin/");
//    else if(bFlag_type == 2)
//        openFilePath->setDirectory(cache_dir +"/usr/bin/");
//    QString exec_path;
//    QStringList strList;
//    if(openFilePath->exec() == QDialog::Accepted)
//    {
//        exec_path = openFilePath->selectedFiles()[0];
//        strList = exec_path.split("/");
//        int nCount = strList.size();
//        QString sPath = "/";
//        exec_path = sPath + strList.at(nCount - 3)+"/"+strList.at(nCount - 2)+"/"+strList.at(nCount -1);
//        if(bFlag_type == 1)
//        {
//            control_xml_1->lExec->setText(exec_path);
//        }
//        else if(bFlag_type == 2)
//        {
//            control_xml_2->lExec->setText(exec_path);
//        }
//    }
//    delete openFilePath;
//}

//opt版
void MainWindow::click_btn_exec()
{
    QFileDialog* openFilePath = new QFileDialog(this);
    openFilePath->setWindowTitle("选择软件执行程序");

    QString* str_dir;
    if(bFlag_type == 1)
        str_dir = new QString(str_Source);
    else if(bFlag_type == 2)
        str_dir = new QString(cache_dir);
    openFilePath->setDirectory(*str_dir);

    QString exec_path;
    if(openFilePath->exec() == QDialog::Accepted)
    {
        exec_path = openFilePath->selectedFiles()[0];
        //如果选择的时包内的相对路径，则截取相对路径
        if( exec_path.mid(0,str_dir->length()) == str_dir )
        {
            exec_path = exec_path.mid(str_dir->length());
        }


        if(bFlag_type == 1)
        {
            control_xml_1->lExec->setText(exec_path);
        }
        else if(bFlag_type == 2)
        {
            control_xml_2->lExec->setText(exec_path);
        }
    }
    delete openFilePath;
}

//"基本信息（必填）" "选择图标按钮"  响应槽
void MainWindow::click_btn_icon()
{
    QFileDialog* openFilePath = new QFileDialog(this);
    openFilePath->setWindowTitle("请选择图标文件");

    QString* str_icon_dir;
    QString name;
    if(bFlag_type == 1){
        str_icon_dir = new QString(str_Source);
        name = control_xml_1->sname_en->text();
    }
    else if(bFlag_type == 2){
        str_icon_dir = new QString(cache_dir);
        name = control_xml_2->sname_en->text();
    }
    openFilePath->setDirectory(*str_icon_dir);
#if 0
    // icon保存在版本/usr/share/icons/hicolor/48x48/apps/name.png版本
    QString icon_save_path = *str_icon_dir + "/usr/share/icons/hicolor/48x48/apps";
#else
    //icon保存在/CPK/icons/name.png版本
    QString icon_save_path = *str_icon_dir + "/CPK/icons";
#endif

#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
    openFilePath->setFilter(tr("Image Files(*.png)"));
#endif
    QString icon_file_path;
    if(openFilePath->exec() == QDialog::Accepted)
    {
        icon_file_path = openFilePath->selectedFiles()[0];

        //创建文件夹
        File fshell1;
        QString a = QString("mkdir -p %1").arg(icon_save_path);
        fshell1.inputShell(a.toLocal8Bit().data());

        int name_start_index = icon_file_path.lastIndexOf("/");
        int suffix_index = icon_file_path.lastIndexOf(".");
//        QString the_name = icon_file_path.mid(name_start_index+1, suffix_index-name_start_index-1);
//        qDebug()<< "the_name ::::   " <<the_name << endl;
        QString tmp = icon_file_path;
        QString icon_rename_file_path = tmp.replace(name_start_index+1, suffix_index-name_start_index-1, name);

        File fshell2;
//        icon_rename_file_path = icon_rename_file_path + "Flag";
        QString b = QString("cp %1 %2").arg(icon_file_path).arg(icon_rename_file_path);
        fshell2.inputShell(b.toLocal8Bit().data());

        File fshell3;
        QString c = QString("mv %1 %2").arg(icon_rename_file_path).arg(icon_save_path);
        fshell3.inputShell(c.toLocal8Bit().data());

        File fshell4;
        QString d = QString("cp %1/%2.png %3").arg(icon_save_path).arg(name).arg(icon_file_path);
        fshell4.inputShell(d.toLocal8Bit().data());

        if(bFlag_type == 1){
            control_xml_1->icon_le->setText(icon_file_path);
        }
        else if(bFlag_type == 2){
            control_xml_2->icon_le->setText(icon_file_path);
        }
        QPixmap pixmap(icon_file_path);
        ui->toolButton_icon->setIcon(QIcon(pixmap));

    }
    delete openFilePath;
}

//读取str_icon_dir + "/CPK/icons/下icon信息
void MainWindow::icon_loadData()
{
    qDebug() << "icon_loadData";
    QString* str_icon_dir;
    QString name;
    if(bFlag_type == 1){
        str_icon_dir = new QString(str_Source);
        name = control_xml_1->sname_en->text();
    }
    else if(bFlag_type == 2){
        str_icon_dir = new QString(cache_dir);
        name = control_xml_2->sname_en->text();
    }

    QString icon_file_path = *str_icon_dir + "/CPK/icons/" + name + ".png";

    QFileInfo fi( icon_file_path );
    if(fi.exists())
    {
        if(bFlag_type == 1){
            if(icon_file_path.length() > 0) control_xml_1->icon_le->setText(icon_file_path);
        }
        else if(bFlag_type == 2){
            if(icon_file_path.length() > 0) control_xml_2->icon_le->setText(icon_file_path);
        }
    }

}

//"基本信息（必填）" "选择启动器"  响应槽
void MainWindow::click_btn_desktop()
{
    QFileDialog* openFilePath = new QFileDialog(this);
    openFilePath->setWindowTitle("请选择启动器文件");

    QString* str_icon_dir;
    QString name;
    if(bFlag_type == 1){
        str_icon_dir = new QString(str_Source);
        name = control_xml_1->sname_en->text();
    }
    else if(bFlag_type == 2){
        str_icon_dir = new QString(cache_dir);
        name = control_xml_2->sname_en->text();
    }
    openFilePath->setDirectory(*str_icon_dir + "/usr/share/applications");

    QString icon_save_path = *str_icon_dir + "/CPK";

#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
    openFilePath->setFilter(tr("Desktop Files(*.desktop)"));
#endif
    QString icon_file_path;
    if(openFilePath->exec() == QDialog::Accepted)
    {
        icon_file_path = openFilePath->selectedFiles()[0];

        //创建文件夹
        File fshell1;
        QString a = QString("mkdir -p %1").arg(icon_save_path);
        fshell1.inputShell(a.toLocal8Bit().data());

        int name_start_index = icon_file_path.lastIndexOf("/");
        int suffix_index = icon_file_path.lastIndexOf(".");
//        QString the_name = icon_file_path.mid(name_start_index+1, suffix_index-name_start_index-1);
//        qDebug()<< "the_name ::::   " <<the_name << endl;
        QString tmp = icon_file_path;
        QString icon_rename_file_path = tmp.replace(name_start_index+1, suffix_index-name_start_index-1, name);

        File fshell2;
//        icon_rename_file_path = icon_rename_file_path + "Flag";
        QString b = QString("cp %1 %2").arg(icon_file_path).arg(icon_rename_file_path);
        fshell2.inputShell(b.toLocal8Bit().data());

        File fshell3;
        QString c = QString("mv %1 %2").arg(icon_rename_file_path).arg(icon_save_path);
        fshell3.inputShell(c.toLocal8Bit().data());

        File fshell4;
        QString d = QString("cp %1/%2.desktop %3").arg(icon_save_path).arg(name).arg(icon_file_path);
        fshell4.inputShell(d.toLocal8Bit().data());

        if(bFlag_type == 1){
            control_xml_1->desktop_le->setText(icon_file_path);
        }
        else if(bFlag_type == 2){
            control_xml_2->desktop_le->setText(icon_file_path);
        }

    }
    delete openFilePath;
}

//读取str_icon_dir + "/usr/share/applications/下desktop信息
void MainWindow::desktop_loadData()
{
    qDebug() << "desktop_loadData";
    QString* str_icon_dir;
    QString name;
    if(bFlag_type == 1){
        str_icon_dir = new QString(str_Source);
        name = control_xml_1->sname_en->text();
    }
    else if(bFlag_type == 2){
        str_icon_dir = new QString(cache_dir);
        name = control_xml_2->sname_en->text();
    }

    QString desktop_file_path = *str_icon_dir + "/usr/share/applications/" + name + ".desktop";

    QFileInfo fi( desktop_file_path );
    if(fi.exists())
    {
        if(bFlag_type == 1){
            if(desktop_file_path.length() > 0) control_xml_1->desktop_le->setText(desktop_file_path);
        }
        else if(bFlag_type == 2){
            if(desktop_file_path.length() > 0) control_xml_2->desktop_le->setText(desktop_file_path);
        }
    }

}

//添加截图按钮（已不使用）
//void MainWindow::click_btn_pic()
//{
//    QFileDialog* openFilePath = new QFileDialog(this);
//    openFilePath->setWindowTitle("请选择截图文件(注意图片名称中不要出现空格斜杠)");

//    QString* str_icon_dir;
//    QString name;
//    if(bFlag_type == 1){
//        str_icon_dir = new QString(str_Source);
//        name = control_xml_1->sname_en->text();
//    }
//    else if(bFlag_type == 2){
//        str_icon_dir = new QString(cache_dir);
//        name = control_xml_2->sname_en->text();
//    }
//    openFilePath->setDirectory(*str_icon_dir);
//#if 0
//    // 截图保存在版本/usr/share/screenshot版本
//    QString icon_save_path = *str_icon_dir + "/usr/share/screenshot";
//#else
//    //截图保存在/CPK/screenshot版本
//    QString icon_save_path = *str_icon_dir + "/CPK/screenshot";
//#endif

//#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
//    openFilePath->setFilter(tr("Image Files(*.jpg *.png)"));
//#endif
//    QString icon_file_path;
//    if(openFilePath->exec() == QDialog::Accepted)
//    {
//        icon_file_path = openFilePath->selectedFiles()[0];

////        qDebug() << "icon_file_path::   " << icon_file_path << endl;

//        File fshell1;
//        QString a = QString("mkdir -p %1").arg(icon_save_path);
//        fshell1.inputShell(a.toLocal8Bit().data());

//        File fshell2;
//        QString b = QString("cp %1 %2").arg(icon_file_path).arg(icon_save_path);
//        fshell2.inputShell(b.toLocal8Bit().data());

//    }
//    delete openFilePath;
//}

//截图详细数据
void MainWindow::slot_screenshot_menu_row_detail(const QModelIndex index)
{
    if(!index.isValid())
        return;

    QStandardItemModel* p_screen_tv_model;
    if(bFlag_type == 1){
        p_screen_tv_model = control_xml_1->tv_screenshot_model;
    }
    else if(bFlag_type == 2){
        p_screen_tv_model = control_xml_2->tv_screenshot_model;
    }

    QToolTip::showText(QCursor::pos(), p_screen_tv_model->itemFromIndex(index)->text());

}

//截图表菜单显示
void MainWindow::slot_screenshot_menu_show( QPoint pos )
{
    QMenu* the_menu = NULL;
    if(bFlag_type == 1)
    {
        the_menu = control_xml_1->st_menu;
    }
    else if(bFlag_type == 2)
    {
        the_menu = control_xml_2->st_menu;
    }

    if( the_menu )
    {
        the_menu->exec(QCursor::pos());
    }
}

//截图表菜单-编辑
void MainWindow::slot_screenshot_menu_edit()
{
    //qDebug() << "slot_screenshot_menu_edit" << endl;

    QModelIndexList selected_list;
    if(bFlag_type == 1)
    {
        selected_list = control_xml_1->tv_screenshot->selectionModel()->selectedRows();
    }
    else if(bFlag_type == 2)
    {
        selected_list = control_xml_2->tv_screenshot->selectionModel()->selectedRows();
    }

    if(selected_list.length() > 0)
    {
        qDebug() << "selected row ::::  " << selected_list.at(0).row() << endl;
    }


    QFileDialog* openFilePath = new QFileDialog(this);
    openFilePath->setWindowTitle("请选择截图文件(注意图片名称中不要出现空格斜杠)");

    QString* str_icon_dir;
    QString name;
    if(bFlag_type == 1){
        str_icon_dir = new QString(str_Source);
        name = control_xml_1->sname_en->text();
    }
    else if(bFlag_type == 2){
        str_icon_dir = new QString(cache_dir);
        name = control_xml_2->sname_en->text();
    }
    openFilePath->setDirectory(*str_icon_dir);
#if 0
    // 截图保存在版本/usr/share/screenshot版本
    QString icon_save_path = *str_icon_dir + "/usr/share/screenshot";
#else
    //截图保存在/CPK/screenshot版本
    QString icon_save_path = *str_icon_dir + "/CPK/screenshot";
#endif

#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
    openFilePath->setFilter(tr("Image Files(*.jpg *.png)"));
#endif
    QString pic_file_path;
    if(openFilePath->exec() == QDialog::Accepted)
    {
        pic_file_path = openFilePath->selectedFiles()[0];

//        qDebug() << "pic_file_path::   " << pic_file_path << endl;

        File fshell1;
        QString a = QString("mkdir -p %1").arg(icon_save_path);
        fshell1.inputShell(a.toLocal8Bit().data());

        File fshell2;
        QString b = QString("cp %1 %2/%3_%4.png").arg(pic_file_path).arg(icon_save_path).arg(name).arg(QString::number(selected_list.at(0).row() + 1));
        fshell2.inputShell(b.toLocal8Bit().data());

    }
    delete openFilePath;

    //重新载入数据
    screenshotmodel_loadData();


}

//截图表菜单-删除
void MainWindow::slot_screenshot_menu_del()
{
    qDebug() << "slot_screenshot_menu_del" << endl;

    QString pc_file_path;
    Xml* the_xml = NULL;
    if(bFlag_type == 1)
    {
        the_xml = control_xml_1;
    }
    else if(bFlag_type == 2)
    {
        the_xml = control_xml_2;
    }
    //获取选中行号
    QModelIndexList selected_list = the_xml->tv_screenshot->selectionModel()->selectedRows();
    //获取文件路径
    if(selected_list.length() > 0)
    {
        int selected_row = selected_list.at(0).row();
        qDebug() << "selected row ::::  " << selected_row << endl;
        qDebug() << the_xml->tv_screenshot_model->item(selected_row,0)->text() << endl;
        pc_file_path = the_xml->tv_screenshot_model->item(selected_row,0)->text();
    }
    //删除文件
    if( pc_file_path.length() > 0 )
    {
        File fshell1;
        QString a = QString("rm %1").arg(pc_file_path);
        fshell1.inputShell(a.toLocal8Bit().data());
    }

    //重新载入数据
    screenshotmodel_loadData();

}

void MainWindow::screenshotmodel_loadData()
{
    qDebug() << "screenshotmodel_loadData" << endl;

    QTableView* p_screen_tv;
    QStandardItemModel* p_screen_tv_model;
    QString name;
    QString* dir;
    if(bFlag_type == 1){
        p_screen_tv = control_xml_1->tv_screenshot;
        p_screen_tv_model = control_xml_1->tv_screenshot_model;
        dir = new QString(str_Source);
        name = control_xml_1->sname_en->text();
        qDebug() << "1    "<<str_Source ;
    }
    else if(bFlag_type == 2){
        p_screen_tv = control_xml_2->tv_screenshot;
        p_screen_tv_model = control_xml_2->tv_screenshot_model;
        dir = new QString(cache_dir);
        name = control_xml_2->sname_en->text();
        qDebug() << "2    "<<cache_dir ;
    }
    qDebug() << "dir :     " << *dir << endl;

#if 0
    //截图保存在/usr/share/screenshot版本
    QString screenshot_save_path = *dir + "/usr/share/screenshot";
#else
    //截图保存在/CPK/screenshot版本
    QString screenshot_save_path = *dir + "/CPK/screenshot";
#endif
    qDebug() << "screenshot_save_path::::    " << screenshot_save_path << endl;
    File fshell1;
    QString a = QString("mkdir -p %1").arg(screenshot_save_path);
    fshell1.inputShell(a.toLocal8Bit().data());

    Pic_model arr_pics[4];
    Pic_model* p_picmModel;
    for(int i = 0; i <= 3; i++)
    {
        p_picmModel = new Pic_model();
        arr_pics[i] = *p_picmModel;

        //读取文件信息到临时文件CPKT_tmp中
        QString b = QString("file %1/%2_%3.png 1>~/CPKT_tmp.info").arg(screenshot_save_path).arg(name).arg(i+1);
        fshell1.inputShell(b.toLocal8Bit().data());

        //从临时文件CPKT_tmp中读取图片信息
        QString file_data;
        QString tmp_path = "";
        tmp_path.append( getenv("HOME") );
        tmp_path.append("/CPKT_tmp.info");
        QFile file(tmp_path);
        if( !file.open(QIODevice::ReadOnly | QIODevice::Text) )
        {
            qDebug()<<"open error.info error!";
        }
        else
        {
            if(file.size())
            {
                QTextCodec * code = QTextCodec::codecForName("utf8");
                QTextStream stream(&file);
                stream.setCodec(code);//对输出流的设置
                while (stream.atEnd() == 0)
                {
                    file_data = stream.readAll();
                    qDebug() << "file_data -----------------\n" << file_data << "---------------------\n";
                }
            }
            file.close();
        }

        //判断是否存在
        QStringList strList = file_data.split(",");
        int nCount = strList.size();
        if( nCount >= 4 ){

    //截图保存在/usr/share/screenshot版本
//            arr_pics[i].setNameAndSize( "/usr/share/screenshot/" +QString::number(i + 1, 10)  + ".png",file_data.split(",").at(1));
    //截图保存在/CPK/screenshot版本
//            arr_pics[i].setNameAndSize( "/CPK/screenshot/" +QString::number(i + 1, 10)  + ".png",file_data.split(",").at(1));
    //显示完整路径版本
            arr_pics[i].setNameAndSize( screenshot_save_path + "/" + name + "_" +QString::number(i + 1, 10)  + ".png",file_data.split(",").at(1));
        }

        //删除临时文件CPKT_tmp
        QString c = QString("rm ~/CPKT_tmp.info");
        fshell1.inputShell(c.toLocal8Bit().data());

    }

    //添加数据到表中，并设置样式
    for(int i = 0; i <= 3; i++)
    {
        p_screen_tv_model->setItem(i,0,new QStandardItem(arr_pics[i].s_name));
        p_screen_tv_model->setItem(i,1,new QStandardItem(arr_pics[i].s_size));

//        p_screen_tv_model->item(i,0)->

        //设置字符位置
        p_screen_tv_model->item(i,0)->setTextAlignment(Qt::AlignLeft);
        p_screen_tv_model->item(i,1)->setTextAlignment(Qt::AlignCenter);
        //设置字符颜色
        if(arr_pics[i].enable)
        {
            p_screen_tv_model->item(i,1)->setForeground(QBrush(QColor(0, 255, 0)));
        }
        else
        {
            p_screen_tv_model->item(i,1)->setForeground(QBrush(QColor(255, 0, 0)));
        }
    }
//    disconnect(p_screen_tv,SIGNAL(doubleClicked(const QModelIndex &)),this,SLOT(slot_screenshot_doubleClicked(QModelIndex)));
    static int i = 0;
    if( i++ );
    else{
        connect(p_screen_tv,SIGNAL(doubleClicked(const QModelIndex &)),this,SLOT(slot_screenshot_doubleClicked(QModelIndex)));
    }
}

//截图表单击响应槽
void MainWindow::slot_screenshot_clicked(const QModelIndex index)
{
    qDebug() << "slot_screenshot_clicked  ：：：  " << index.row() << endl;
}

//截图表双击响应槽（选择截图文件，修改覆盖）
void MainWindow::slot_screenshot_doubleClicked(const QModelIndex index)
{
    qDebug() << "screenshot_doubleClicked  :::  " << index.row() << endl;

    QFileDialog* openFilePath = new QFileDialog(this);
    openFilePath->setWindowTitle("请选择截图文件(注意图片名称中不要出现空格斜杠)");

    QString* str_icon_dir;
    QString name;
    if(bFlag_type == 1){
        str_icon_dir = new QString(str_Source);
        name = control_xml_1->sname_en->text();
    }
    else if(bFlag_type == 2){
        str_icon_dir = new QString(cache_dir);
        name = control_xml_2->sname_en->text();
    }
    openFilePath->setDirectory(*str_icon_dir);
#if 0
    // 截图保存在版本/usr/share/screenshot版本
    QString icon_save_path = *str_icon_dir + "/usr/share/screenshot";
#else
    //截图保存在/CPK/screenshot版本
    QString icon_save_path = *str_icon_dir + "/CPK/screenshot";
#endif

#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
    openFilePath->setFilter(tr("Image Files(*.jpg *.png)"));
#endif
    QString pic_file_path;
    if(openFilePath->exec() == QDialog::Accepted)
    {
        pic_file_path = openFilePath->selectedFiles()[0];

//        qDebug() << "pic_file_path::   " << pic_file_path << endl;

        File fshell1;
        QString a = QString("mkdir -p %1").arg(icon_save_path);
        fshell1.inputShell(a.toLocal8Bit().data());

        File fshell2;
        QString b = QString("cp %1 %2/%3_%4.png").arg(pic_file_path).arg(icon_save_path).arg(name).arg(QString::number(index.row() + 1));
        fshell2.inputShell(b.toLocal8Bit().data());

    }
    delete openFilePath;

    //重新载入数据
    screenshotmodel_loadData();

}

//重置图标文件名称
void MainWindow::reset_iconFileName()
{
    qDebug() << "reset_iconFileName" << endl;
    QString name_now;
    QString* str_icon_dir;
    if(bFlag_type == 1){
        str_icon_dir = new QString(str_Source);
        name_now = control_xml_1->sname_en->text();
        qDebug() << "1    "<<str_Source ;
    }
    else if(bFlag_type == 2){
        str_icon_dir = new QString(cache_dir);
        name_now = control_xml_2->sname_en->text();
        qDebug() << "2    "<<cache_dir ;
    }

    if(name_now.length() > 0)
    {
#if 0
        // icon保存在版本/usr/share/icons/hicolor/48x48/apps/name.png版本
        QString icon_save_path = *str_icon_dir + "/usr/share/icons/hicolor/48x48/apps";
#else
        //icon保存在/CPK/icons/hicolor/48x48/apps/name.png版本
        QString icon_save_path = *str_icon_dir + "/CPK/icons";
#endif

        File fshell1;
        QString a = QString("mv %1/* %1/%2.png").arg(icon_save_path).arg(name_now);
        fshell1.inputShell(a.toLocal8Bit().data());
    }

}

//重置截图文件名称
void MainWindow::reset_screenshotFileName()
{
    qDebug() << "reset_screenshotFileName" << endl;
    QString name_now;
    QString* str_pic_dir;
    if(bFlag_type == 1){
        str_pic_dir = new QString(str_Source);
        name_now = control_xml_1->sname_en->text();
        qDebug() << "1    "<<str_Source ;
    }
    else if(bFlag_type == 2){
        str_pic_dir = new QString(cache_dir);
        name_now = control_xml_2->sname_en->text();
        qDebug() << "2    "<<cache_dir ;
    }

    if(name_now.length() > 0)
    {
#if 0
        // 截图保存在版本/usr/share/screenshot版本
        QString pic_save_path = *str_pic_dir + "/usr/share/screenshot";
#else
        //截图保存在/CPK/screenshot版本
        QString pic_save_path = *str_pic_dir + "/CPK/screenshot";
#endif
        //读取截图文件夹下文件名到临时文件中
        File fshell1;
        QString a = QString("ls %1 1>~/screenshot_tmp.info").arg(pic_save_path);
        fshell1.inputShell(a.toLocal8Bit().data());

        //从临时文件screenshot_tmp.info中读取图片信息
        QString file_data;
        QString tmp_path = "";
        tmp_path.append( getenv("HOME") );
        tmp_path.append("/screenshot_tmp.info");
        QFile file(tmp_path);
        if( !file.open(QIODevice::ReadOnly | QIODevice::Text) )
        {
            qDebug()<<"open error.info error!";
        }
        else
        {
            if(file.size())
            {
                QTextCodec * code = QTextCodec::codecForName("utf8");
                QTextStream stream(&file);
                stream.setCodec(code);//对输出流的设置
                while (stream.atEnd() == 0)
                {
                    file_data = stream.readAll();
                    qDebug() << "file_data -----------------\n" << file_data << "---------------------\n";
                }
            }
            file.close();
        }

        //判断是否存在
        QStringList strList = file_data.split("\n");
        int nCount = strList.size();
        for(int i = 0; i < nCount && strList.at(i).length() > 0 && i < 4; i++ )
        {

            File fshell2;
            QString b = QString("mv %1/%2 %1/%3_%4.png").arg(pic_save_path).arg(strList.at(i)).arg(name_now).arg(i + 1);
            fshell2.inputShell(b.toLocal8Bit().data());
            qDebug() << i + 1 << "::   " << strList.at(i) << "   " << b << endl;
        }

        //删除临时文件
        File fshell2;
        QString b = QString("rm ~/screenshot_tmp.info");
        fshell2.inputShell(b.toLocal8Bit().data());

    }

}


//关闭按钮响应槽
void MainWindow::click_closebutton()
{
    this->close();
}
//最小化按钮响应槽
void MainWindow::click_minimizebutton()
{
    qDebug() << "Min clicked";
    this->showMinimized();
}
//帮助按钮响应槽
void MainWindow::click_helpbutton()
{
    QFileInfo fi=QFileInfo("/usr/share/cpktransform/usermanual.pdf");
    QString filePath;
    filePath=fi.absolutePath();
    QDesktopServices::openUrl(QUrl::fromLocalFile(filePath+"/usermanual.pdf"));

//    QFileInfo fi=QFileInfo("/usr/share/cpktransform/usermanual.pdf");
//    bool b_openPDF = QDesktopServices::openUrl(QUrl::fromLocalFile(fi.absolutePath()+"/usermanual.pdf"));
//    if( b_openPDF ){
//        qDebug() << "openPDF error";
//        emit slot_Msg_error("1.帮助文件不存在");
//    }

}

//page_2转包页，打包按钮toolButton_11响应槽
void MainWindow::click_transbutton()
{
    this->progreddBarEnable(true);

    if(control_xml_2->sname_en->text().isEmpty())
        control_xml_2->sname_en->m_timer.start();
    else
    {
        if( control_xml_2->sname->text().isEmpty() )
            control_xml_2->sname->m_timer.start();
        else
        {
            if(control_xml_2->l_1->text().isEmpty() )
                control_xml_2->l_1->m_timer.start();
            else
            {
                if(control_xml_2->l_2->text().isEmpty() )
                    control_xml_2->l_2->m_timer.start();
                else
                {
                    if(control_xml_2->l_3->text().isEmpty()  )
                        control_xml_2->l_3->m_timer.start();
                    else
                    {
                        if( control_xml_2->larch->text().isEmpty() )
                            control_xml_2->larch->m_timer.start();
                        else
                        {
                            if(control_xml_2->lExec->text().isEmpty())
                                control_xml_2->lExec->m_timer.start();
                            else  if(script_line->text().isEmpty())
                                script_line->m_timer.start();
                        }
                    }
                }
            }
        }
    }

    if(!control_xml_2->sname_en->text().isEmpty() &&
            !control_xml_2->sname->text().isEmpty() &&
            !control_xml_2->l_1->text().isEmpty() &&
            !control_xml_2->l_2->text().isEmpty() &&
            !control_xml_2->l_3->text().isEmpty()  &&
            !control_xml_2->larch->text().isEmpty() &&
            !control_xml_2->lExec->text().isEmpty() &&
            !script_line->text().isEmpty())
    {
        //读取desktop文件到CPK下
        create_desktop(cache_dir);
        delete_debian_and_rmptxt(cache_dir);
        //生成filelist文件
        //              cpkfilelistgeneration();
        //            生成filelist文件
        //            cpkfilelistgeneration();
        Thread* thread_py = new Thread(bFlag_type,str_Source, cache_dir, py_filelist);
        thread_py->start();
        connect(thread_py, SIGNAL(signal_Msg_py_end(int)), this, SLOT(slot_Msg_py_end(int)));
        connect(thread_py, SIGNAL(signal_Msg_error(QString)), this, SLOT(slot_Msg_pack_end(QString)));
//        这部分代码置于slot_Msg_py_end(int thread_type)中
//                control_xml_2->create_xml(cache_dir);
//        //重置安装脚本文件
//        set_script_into_file();
//        //打包
//        if(!ui->lineEdit_target_2->text().isEmpty())
//        {
//            timer2 = new QTimer(this);
//            connect(timer2,SIGNAL(timeout()),this,SLOT(timeUpDate2()));
//            timer2->start(200);
//            ui->progressBar_2->setFormat("正在打包中...");
//            QStringList name = soft_name.split("_");
//            //拼接新的包路径和名称
//            QString dist_name = ui->lineEdit_target_2->text() +"/"+control_xml_2->sname_en->text()+"_"+control_xml_2->l_1->text()+"."+control_xml_2->l_2->text()+"."+control_xml_2->l_3->text() +"_"+ control_xml_2->larch->text()+".cpk";
//            QString Command = QString("cpkg --pack %1  %2").arg(cache_dir).arg(dist_name);
//            thread_package = new Thread(Command);
//            thread_package->cache_dir = cache_dir;
//            connect(thread_package, SIGNAL(signal_Msg_pack_end(QString)),
//                    this, SLOT(slot_Msg_pack_end(QString)));
//            connect(thread_package, SIGNAL(signal_Msg_error(QString)), this, SLOT(slot_Msg_pack_end(QString)));
//            thread_package->start();
//        }

    }
}

void MainWindow::click_btn_selbutton()
{
    QString dir = QFileDialog::getExistingDirectory(this, "选择目录", "/home", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::DontUseNativeDialog);
    if(!dir.isEmpty())
    {
        ui->lineEdit_target_2->setText(dir);
        str_Target = ui->lineEdit_target_2->text();
    }


}

void MainWindow::delete_debian_and_rmptxt(QString cache_dir)
{
    //针对deb包，判断是否存在DEBIAN文件夹
    //Todo
    QFileInfo fi(cache_dir+"/DEBIAN");
    if(fi.exists())
    {
        qDebug("exist /DEBIAN!\n");
        QString a;
        a = QString("rm -rf %1").arg(cache_dir+"/DEBIAN");
        system(a.toLocal8Bit().data());
    }
    fi.setFile(cache_dir+"/tmp_rpm.txt");
    if(fi.exists())
    {
        qDebug("exist /tmp_rpm.txt!\n");
        QString a;
        a = QString("rm %1").arg(cache_dir+"/tmp_rpm.txt");
        system(a.toLocal8Bit().data());
    }


}

////
//void MainWindow::clearUIData()
//{
////    转包详情页左侧详细信息清空
//    if(ui->label_packname)
//    {
//        ui->label_packname->setText(" Unknown");
//    }
//    if(ui->label_version)
//    {
//        ui->label_version->setText(" Unknown");
//    }
//    if(ui->label_arch)
//    {
//        ui->label_arch->setText(" Unknown");
//    }
//    if(ui->label_maintainer)
//    {
//        ui->label_maintainer->setText(" Unknown");
//    }
//    if(ui->label_installedSize)
//    {
//        ui->label_installedSize->setText(" Unknown");
//    }
//    if(ui->label_section)
//    {
//        ui->label_section->setText(" Unknown");
//    }
//    if(ui->label_hp)
//    {
//        ui->label_hp->setText(" Unknown");
//    }
////    打包页xml数据清空
//    if(control_xml_1)
//    {
//        control_xml_1->delete_data();
//    }
////    转包页xml数据清空
//    if(control_xml_2)
//    {
//        control_xml_2->delete_data();
//    }
//}

//转包，解压按钮响应中的一步，      解压，并提取软件包信息，生成详情页，成功返回0，失败返回-1
int MainWindow::readConf(QString path, QString name)
{
    delete_data();
//    clearUIData();
//    python_init();
    //设置显示包图片
    QString icon = cache_dir+"/usr/share/icons/hicolor/48x48/apps/";
//    QString icon = cache_dir+"/CPK/icons/";
    QFileInfoList list = QDir(icon).entryInfoList();
//    使用默认图标
    QPixmap  p;
    p.load("/usr/share/cpktransform/images/package.png");
    ui->toolButton_icon->setIcon(QIcon(p));
//    有图标设置新图标
    for (int i = 0; i < list.size(); ++i) {
        QFileInfo fileInfo = list.at(i);
        QStringList strList = fileInfo.fileName().split(".");
        if(!strcmp(strList.at(1).toLocal8Bit().data(), "png"))
        {
            QString icon_path = fileInfo.filePath();
            QPixmap pixmap(icon_path);
            ui->toolButton_icon->setIcon(QIcon(pixmap));
        }
    }
    ui->label->setStyleSheet("color:white;font-size:12px;font-weight:bold;");
    ui->label_2->setStyleSheet("color:white;font-size:12px;font-weight:bold;");
    ui->label_3->setStyleSheet("color:white;font-size:12px;font-weight:bold;");
    ui->label_4->setStyleSheet("color:white;font-size:12px;font-weight:bold;");
    ui->label_5->setStyleSheet("color:white;font-size:12px;font-weight:bold;");
    ui->label_6->setStyleSheet("color:white;font-size:12px;font-weight:bold;");
    ui->label_packname->setStyleSheet("color:white;font-size:12px;");
    ui->label_maintainer->setStyleSheet("color:white;font-size:11px;");
    ui->label_version->setStyleSheet("color:white;font-size:11px;");
    ui->label_arch->setStyleSheet("color:white;font-size:11px;");
    ui->label_installedSize->setStyleSheet("color:white;font-size:11px;");
    ui->label_section->setStyleSheet("color:white;font-size:11px;");
    ui->label_hp->setStyleSheet("color:white;font-size:11px;");

    ui->label->setFixedHeight(20);
    ui->label_2->setFixedHeight(20);
    ui->label_3->setFixedHeight(20);
    ui->label_4->setFixedHeight(20);
    ui->label_5->setFixedHeight(20);
    ui->label_6->setFixedHeight(20);
    ui->label_maintainer->setFixedHeight(18);
    ui->label_maintainer->setFixedWidth(140);
    ui->label_section->setFixedHeight(18);
    ui->label_section->setFixedWidth(140);
    ui->label_version->setFixedHeight(18);
    ui->label_version->setFixedWidth(140);
    ui->label_arch->setFixedHeight(18);
    ui->label_arch->setFixedWidth(140);
    ui->label_installedSize->setFixedHeight(18);
    ui->label_installedSize->setFixedWidth(140);
    ui->label_hp->setFixedHeight(18);
    ui->label_hp->setFixedWidth(140);
    ui->label_occupy_1->setFixedHeight(10);
    ui->label_occupy_2->setFixedHeight(10);

    QStringList strList;
    strList = name.split(".");
    int nCount = strList.size();
    if(!strcmp(strList.at(nCount  -1).toLocal8Bit().data(), "deb"))
    {
        PyObject* pModule;
        PyObject* pFunction;
        PyObject* pArgs;
        PyObject* pRetVal = NULL;
        //导入模块
        pModule = PyImport_ImportModule("debinfo");
        if(!pModule){
            printf("import python debinfo failed!\n");
            //                return -1;
            emit signal_Msg_error("解压过程中发生错误！\n\n详细错误信息：\nimport python debinfo failed!\n");
            return -1;
        }
        else
        {
            printf("import python debinfo  succeed!\n");
        }
        //查找函数
        pFunction = PyObject_GetAttrString(pModule, "getDebInfo");
        if(!pFunction){
            printf("get python function failed!\n");
            //              return -1;
            emit signal_Msg_error("解压过程中发生错误！\n\n详细错误信息：\nget python function failed!\n");
            return -1;
        }
        //创建参数
        pArgs = PyTuple_New(1);
        PyTuple_SetItem(pArgs, 0, Py_BuildValue("s", path.toLocal8Bit().data()));
        //函数调用
        pRetVal = PyObject_CallObject(pFunction, pArgs);
        char* strValue;
        PyArg_Parse(pRetVal, "s", &strValue);
        QStringList strList;
        strList = QString::fromLocal8Bit(strValue).split("&");
        QFont font(ui->label_maintainer->font());
        QFontMetrics fm(font);
        control_xml_2->sname_en->setText(strList.at(0));
        if(strList.at(0) != NULL && strcmp(strList.at(0).toLocal8Bit().data(),""))
            ui->label_packname->setText(strList.at(0));
        ui->label_version->setText(" "+fm.elidedText(QString(strList.at(1)),
                                                     Qt::ElideRight, ui->label_version->width()));
        //            qDebug() << "ui->label_version  ----------" <<ui->label_version->text();
        ui->label_arch->setText(" "+fm.elidedText(QString(strList.at(2)),
                                                  Qt::ElideRight, ui->label_arch->width()));
        control_xml_2->larch->setText(strList.at(2));
        ui->label_maintainer->setText(" "+fm.elidedText(QString(strList.at(3)),
                                                        Qt::ElideRight, ui->label_maintainer->width()));
        ui->label_installedSize->setText(" "+fm.elidedText(QString(strList.at(4)),
                                                           Qt::ElideRight, ui->label_installedSize->width())+"B");
        ui->label_section->setText(" "+fm.elidedText(QString(strList.at(5)),
                                                     Qt::ElideRight, ui->label_section->width()));
        ui->label_hp->setText(" "+fm.elidedText(QString(strList.at(6)),
                                                Qt::ElideRight, ui->label_hp->width()));
        script_line->setText(strList.at(0) +".install");
        control_xml_2->str_soft_hp = ui->label_hp->text();

        pFunction = PyObject_GetAttrString(pModule, "getDebDescription");
        if(!pFunction){
            printf("get python function failed!\n");
            emit signal_Msg_error("解压过程中发生错误！\n\n详细错误信息：\nget python function failed!\n");
            return -1;
        }
        pArgs = PyTuple_New(1);
        PyTuple_SetItem(pArgs, 0, Py_BuildValue("s", path.toLocal8Bit().data()));
        pRetVal = PyObject_CallObject(pFunction, pArgs);
        PyArg_Parse(pRetVal, "s", &strValue);
        control_xml_2->tldesc_en->setText(strValue);
        QStringList summary ;
        summary = QString::fromLocal8Bit(strValue).split(".");
        control_xml_2->lsdesc_en->setText(summary.at(0));

        Py_DECREF(pModule);
        Py_DECREF(pFunction);
        return 0;
    }
    else if(!strcmp(strList.at(nCount  -1).toLocal8Bit().data(), "rpm"))
    {
        char result[1024*4]="";                   //定义存放结果的字符串数组
        File f;
        ErrorInfo* error_info = new ErrorInfo();
        QString strcmd = QString("cd %1 && rpm -qpi %2 2>$HOME/error.info").arg(debfile_path).arg(name);
        if( error_info->judge_error() )
        {
            emit signal_Msg_error("读取rpm信息过程中发生错误！\n可能的错误原因\n1.未安装rpm包管理工具\n\n详细错误信息：\n" + error_info->errorInfoDes);
            return -1;
        }
        else
        {
            if(1==f.execmd(strcmd.toLocal8Bit().data(),result)){
                qDebug() << "1\n" << result;
                if( strlen( result) == 0 )
                {
                    emit signal_Msg_error("读取rpm信息过程中发生错误！\n可能的错误原因\n1.未安装rpm包管理工具\n\n详细错误信息：\n" + error_info->errorInfoDes);
                    return -1;
                }
            }

            QTextCodec * code = QTextCodec::codecForName("utf8");

            QString fname = cache_dir+"/tmp_rpm.txt";
            QFile file(fname);
            file.open(QIODevice::ReadWrite);
            QTextStream in(&file);
            in.setCodec(code);
            in<<result<<"\n";
            file.close();
            QString Name = f.value_of_the_key(fname.toLocal8Bit().data(), "Name");
            QString Version = f.value_of_the_key(fname.toLocal8Bit().data(), "Version");
            QString Architecture = f.value_of_the_key(fname.toLocal8Bit().data(), "Architecture");
            QString Vendor = f.value_of_the_key(fname.toLocal8Bit().data(), "Vendor");
            QString Size = f.value_of_the_key(fname.toLocal8Bit().data(), "Size");
            QString Group = f.value_of_the_key(fname.toLocal8Bit().data(), "Group");

            QString URL = f.value_of_the_key(fname.toLocal8Bit().data(), "URL");
            //          QString Summary = f.value_of_the_key(fname.toLocal8Bit().data(), "Summary");
            QString Summary = f.value_of_the_key(fname.toLocal8Bit().data(), "Summary");
            //          QString Description =  f.value_of_the_key(fname.toLocal8Bit().data(), "Description");
            QString  Description =  f.value_of_the_key(fname.toLocal8Bit().data(), "Description");
            //          qDebug() << Description;

            if(Name.isEmpty() || Name.isNull())
                ui->label_packname->setText(" Unknown");
            else
                ui->label_packname->setText(f.value_of_the_key(fname.toLocal8Bit().data(), "Name"));
            if(Version.isEmpty() || Version.isNull())
                ui->label_version->setText(" Unknown");
            else
                ui->label_version->setText(" "+ f.value_of_the_key(fname.toLocal8Bit().data(), "Version"));
            if(Architecture.isEmpty() || Architecture.isNull())
                ui->label_arch->setText(" Unknown");
            else
                ui->label_arch->setText(" "+ f.value_of_the_key(fname.toLocal8Bit().data(), "Architecture"));
            if(Vendor.isEmpty() || Vendor.isEmpty())
                ui->label_maintainer->setText(" Unknown");
            else
                ui->label_maintainer->setText(" "  + f.value_of_the_key(fname.toLocal8Bit().data(), "Vendor"));
            if(Size.isEmpty() || Size.isNull())
                ui->label_installedSize->setText(" Unknown");
            else
                ui->label_installedSize->setText(" " + f.value_of_the_key(fname.toLocal8Bit().data(), "Size"));
            if(URL.isEmpty() || URL.isNull())
                ui->label_hp->setText(" Unknown");
            else
                ui->label_hp->setText(" " + f.value_of_the_key(fname.toLocal8Bit().data(), "URL"));
            if(Group.isEmpty() || Group.isNull())
                ui->label_section->setText(" Unknown");
            else
                ui->label_section->setText(" " + f.value_of_the_key(fname.toLocal8Bit().data(), "Group"));

            control_xml_2->larch->setText(f.value_of_the_key(fname.toLocal8Bit().data(), "Architecture"));
            control_xml_2->sname_en->setText(f.value_of_the_key(fname.toLocal8Bit().data(), "Name"));
            control_xml_2->str_soft_hp = ui->label_hp->text();
            control_xml_2->lprotocol->setText(f.value_of_the_key(fname.toLocal8Bit().data(), "License"));
            control_xml_2->lsdesc_en->setText(f.value_of_the_key(fname.toLocal8Bit().data(), "Summary"));
            control_xml_2->tldesc_en->setText(f.value_of_the_key(fname.toLocal8Bit().data(), "Description"));
            control_xml_2->l_name->setText(f.value_of_the_key(fname.toLocal8Bit().data(), "Vendor"));
//            control_xml_2->l_pg->setText(f.value_of_the_key(fname.toLocal8Bit().data(), "URL"));
            script_line->setText(f.value_of_the_key(fname.toLocal8Bit().data(), "Name") +".install");

            QStringList strList = Version.split(".");
            int nCount = strList.size();
            if( nCount >= 3 ){
                control_xml_2->l_1->setText(Version.split(".").at(0));
                control_xml_2->l_2->setText(Version.split(".").at(1));
                control_xml_2->l_3->setText(Version.split(".").at(2));
            }
        }


    }
    return 0;
}

void MainWindow::slot_get_move_event(QPoint p1,QPoint p2)
{
    //移动主窗口
    this->move(this->pos() + p1 - p2);
}

void MainWindow::read_xml(QString filename)
{
    QFile file(filename);
    if (!file.open(QIODevice::ReadOnly | QFile::Text)) {
        qDebug()<<"open for read error..." ;
    }
    QString errorStr;
    int errorLine;
    int errorColumn;

    QDomDocument doc;
    if (!doc.setContent(&file, false, &errorStr, &errorLine, &errorColumn)) {
        qDebug()<<"setcontent error..." ;
        file.close();
    }
    file.close();
    QDomElement root = doc.documentElement();
    if (root.tagName() != "ipconfig") {
        qDebug()<<"root.tagname != ipconfig..." ;
    }
    QDomNode node = root.firstChild();
    while(!node.isNull())
    {
        if(node.isElement())
        {
            QDomElement element = node.toElement();
            qDebug() << qPrintable(element.tagName())<<qPrintable(element.attribute("id"));
            QDomNodeList list = element.childNodes();
            for(int i = 0;i < list.count();i++)
            {
                QDomNode nodechild = list.at(i);
                if(nodechild.isElement())
                {
                    qDebug() << "    " << qPrintable(nodechild.toElement().tagName()) << qPrintable(nodechild.toElement().text());
                }
            }
        }
        node = node.nextSibling();
    }
}

//生成desktop文件
void MainWindow::create_desktop(QString filename)
{
#if 0
    QStringList strlist = soft_name.split("_");
    QString fname  = filename +"/usr/share/applications/" + strlist.at(0)+".desktop";
    qDebug()<< fname.toLocal8Bit().data();
    QString a;
    QFileInfo file(fname);
    if(file.exists())
    {
        //文件存在
        a = QString("cp %1 %2").arg(fname).arg(cache_dir + "/CPK");
        qDebug()<< cache_dir +"/CPK";
        system(a.toStdString().c_str());
    }
#else
    QString file_applications = filename+"/usr/share/applications/";
    QFileInfoList list = QDir(file_applications).entryInfoList();
    File f;
    //int a = list.size();
    qDebug()<< "     Bytes Filename";
    for (int i = 0; i < list.size(); ++i) {
        QFileInfo fileInfo = list.at(i);
        qDebug()<< qPrintable(QString("%1 %2").arg(fileInfo.size(), 10)
                              .arg(fileInfo.fileName()));
        QStringList strList = fileInfo.fileName().split(".");
        if(!strcmp(strList.at(1).toLocal8Bit().data(), "desktop"))
        {
            QString a = QString("cp %1 %2").arg(fileInfo.filePath()).arg(filename+"/CPK/");
            //system(a.toLocal8Bit().data());
            f.inputShell(a.toLocal8Bit().data());
        }
    }
#endif
}

//这部分代码已由Thread实现
//生成filelist文件
//0 succeful -1 error
//int MainWindow::cpkfilelistgeneration()
//{
//    //预先生成CPK文件夹
//    QString cpk_path;
//    if(bFlag_type == 1) //打包
//         cpk_path = str_Source +"/CPK";
//    else if(bFlag_type == 2) //转包
//         cpk_path = cache_dir +"/CPK";
//    QFileInfo fi(cpk_path.toLocal8Bit().data());
//    if(fi.exists())
//    {
//        qDebug("存在CPK文件夹!（生成filelist）\n");
//        //return -1;
//    }
//    else
//    {
//         //创建文件夹
//         if(mkdir(cpk_path.toLocal8Bit().data(), 00700) < 0)
//         {
////              printf("mkdir -cpkfilelistgeneration error!\n");
////              exit(1);
//              emit signal_Msg_error("生成filelist文件过程中发生错误\n\n详细错误信息：\nmkdir -cpkfilelistgeneration error!\n");
//              return -1;
//         }
//    }

//    PyObject* pModule;
//    PyObject* pFunction;
//    PyObject* pArgs;

//      pModule = PyImport_ImportModule("filelist");
//      if(!pModule){
//          printf("import python  filelist failed!\n");
//                                  emit signal_Msg_error("生成filelist文件过程中发生错误\n\n详细错误信息：\nimport python  filelist failed!\n");
//                                  return -1;
//        }
//      else
//      {
//          printf("import python  filelist succeed!\n");
//      }
//      pFunction = PyObject_GetAttrString(pModule, "gen_filelist");
//      if(!pFunction){
//        printf("get python function failed!\n");
////        return -1;
//                                  emit signal_Msg_error("生成filelist文件过程中发生错误\n\n详细错误信息：\nget python function failed!\n");
//                                  return -1;
//        }
//      pArgs = PyTuple_New(1);
//      if(bFlag_type == 1) //打包
//            PyTuple_SetItem(pArgs, 0, Py_BuildValue("s", str_Source.toLocal8Bit().data()));
//      else if(bFlag_type == 2) //转包
//            PyTuple_SetItem(pArgs, 0, Py_BuildValue("s", cache_dir.toLocal8Bit().data()));
//      PyObject_CallObject(pFunction, pArgs);

//      Py_DECREF(pModule);
//      Py_DECREF(pFunction);
//      Py_DECREF(pArgs);
//      return 0;
//}

//生成安装脚本文件
int MainWindow::cpkscriptgeneration()
{
    //预先生成CPK文件夹Mencius
    QString cpk_path = cache_dir +"/CPK";
    QFileInfo fi(cpk_path.toLocal8Bit().data());
    if(fi.exists())
    {
        qDebug("存在CPK文件夹!2\n");
        //return -1;
    }
    else
    {
        //创建文件夹
        if(mkdir(cpk_path.toLocal8Bit().data(), 00700) < 0)
        {
            //              printf("mkdir -cpkscriptgeneration error!\n");
            //              exit(1);
            emit signal_Msg_error("生成安装脚本文件过程中发生错误\n\n详细错误信息：\nmkdir -cpkscriptgeneration error!\n");
            return -1;
        }
    }

    PyObject* pModule;
    PyObject* pFunction;
    PyObject* pArgs;
    PyObject* pRetVal = NULL;

    pModule = PyImport_ImportModule("install_sricpt");
    if(!pModule){
        printf("import python install_sricpt failed!\n");
        //          return -1;
        emit signal_Msg_error("生成安装脚本文件过程中发生错误\n\n详细错误信息：\nimport python install_sricpt failed!\n");
        return -1;
    }
    else
    {
        printf("import python install_sricpt  succeed!\n");
    }
    pFunction = PyObject_GetAttrString(pModule, "install_generation");
    if(!pFunction){
        printf("get python function failed!\n");
        //        return -1;
        emit signal_Msg_error("生成安装脚本文件过程中发生错误\n\n详细错误信息：\nget python function failed!\n");
        return -1;
    }
    pArgs = PyTuple_New(2);
    QStringList name = soft_name.split("_");
    QString name_ = control_xml_2->sname_en->text();
    if(name_ == "")
        name_ = name.at(0);
    PyTuple_SetItem(pArgs, 0, Py_BuildValue("s", cache_dir.toLocal8Bit().data()));
    PyTuple_SetItem(pArgs, 1, Py_BuildValue("s",name_.toLocal8Bit().data()));
    pRetVal = PyObject_CallObject(pFunction, pArgs);
    char* strValue;
    PyArg_Parse(pRetVal, "s", &strValue);
    script_edit->setText(strValue);
    Py_DECREF(pModule);
    Py_DECREF(pFunction);
    return 0;
}

//重置安装脚本文件
int MainWindow::set_script_into_file()
{
    //检测脚本文件是否存在
    //将CPK文件夹中旧install文件删除
    QString strCPK = cache_dir+"/CPK/";
    QFileInfoList list = QDir(strCPK).entryInfoList();
    for(int i = 0; i < list.size(); ++i){
        QFileInfo fileInfo = list.at(i);
        QString name = fileInfo.fileName();
        QStringList strList = name.split(".");
        if(strList.size() == 2 && !strcmp(strList.at(1).toLocal8Bit().data(),"install"))
        {
            QString path = fileInfo.filePath();
            QString delete_script = QString("rm %1").arg(path);
            system(delete_script.toLocal8Bit().data());
        }
    }

    PyObject* pModule ;
    PyObject* pFunction;
    PyObject* pArgs;
    PyObject* pRetVal = NULL;
    pModule = PyImport_ImportModule("set_script");
    if(!pModule){
        printf("import python set_script failed!\n");
        //        return -1;
        emit signal_Msg_error("重置安装脚本文件中发生错误\n\n详细错误信息：\nimport python set_script failed!\n");
        return -1;
    }
    else
    {
        printf("import python script  succeed!\n");
    }
    pFunction = PyObject_GetAttrString(pModule, "write_script");
    if(!pFunction){
        printf("get python function failed!\n");
        //      return -1;
        emit signal_Msg_error("重置安装脚本文件中发生错误\n\n详细错误信息：\nget python function failed!\n");
        return -1;
    }
    pArgs = PyTuple_New(2);
    //QStringList name = soft_name.split("_");
    QString install_path = strCPK + script_line->text();
    PyTuple_SetItem(pArgs, 0, Py_BuildValue("s", install_path.toLocal8Bit().data()));
    PyTuple_SetItem(pArgs, 1, Py_BuildValue("s", script_edit->toPlainText().toLocal8Bit().data()));
    pRetVal = PyObject_CallObject(pFunction, pArgs);
    char* strValue;
    PyArg_Parse(pRetVal, "s", &strValue);
    Py_DECREF(pModule);
    Py_DECREF(pFunction);
    return 0;
}

void MainWindow::process_Protocol(int index)
{
    switch(index)
    {
    case 0:
    {
        control_xml_1->m_strLicense = "GPL";
        control_xml_1->lprotocol->setText("GPL");
        break;
    }
    case 1:
    {
        control_xml_1->m_strLicense = "BSD";
        control_xml_1->lprotocol->setText("BSD");
        break;
    }
    case 2:
    {
        control_xml_1->m_strLicense = "MIT";
        control_xml_1->lprotocol->setText("MIT");
        break;
    }
    case 3:
    {
        control_xml_1->m_strLicense = "Distributable";
        control_xml_1->lprotocol->setText("Distributable");
        break;
    }
    case 4:
    {
        control_xml_1->m_strLicense = "Commercial";
        control_xml_1->lprotocol->setText("Commercial");
        break;
    }
    case 5:
    {
        control_xml_1->m_strLicense = "Share";
        control_xml_1->lprotocol->setText("Share");
        break;
    }
    case 6:
    {
        control_xml_1->m_strLicense = "other";
        control_xml_1->lprotocol->setText("");
        control_xml_1->lprotocol->setPlaceholderText("输入协议名称");
        break;
    }
    default:
        break;
    }
}

void MainWindow::process_Protocol2(int index)
{
    switch(index)
    {
    case 0:
    {
        control_xml_2->m_strLicense = "GPL";
        control_xml_2->lprotocol->setText("GPL");
        break;
    }
    case 1:
    {
        control_xml_2->m_strLicense = "BSD";
        control_xml_2->lprotocol->setText("BSD");
        break;
    }
    case 2:
    {
        control_xml_2->m_strLicense = "MIT";
        control_xml_2->lprotocol->setText("MIT");
        break;
    }
    case 3:
    {
        control_xml_2->m_strLicense = "Distributable";
        control_xml_2->lprotocol->setText("Distributable");
        break;
    }
    case 4:
    {
        control_xml_2->m_strLicense = "Commercial";
        control_xml_2->lprotocol->setText("Commercial");
        break;
    }
    case 5:
    {
        control_xml_2->m_strLicense = "Share";
        control_xml_2->lprotocol->setText("Share");
        break;
    }
    case 6:
    {
        control_xml_2->m_strLicense = "other";
        control_xml_2->lprotocol->setText("");
        control_xml_2->lprotocol->setPlaceholderText("输入协议名称");
        break;
    }
    default:
        break;
    }
}

void MainWindow::click_btn_transbutton()
{
    this->progreddBarEnable(false);
    QPixmap p_title1;
    p_title1.load("/usr/share/cpktransform/images/title_1.png");
    QPalette   palette_title1;
    palette_title1.setBrush(t->backgroundRole(),QBrush(p_title1));
    t->setPalette(palette_title1);
    t->setFixedWidth(p_title1.width());
    t->setFixedHeight(p_title1.height());
    ui->progressBar->setValue(0);
    ui->progressBar->setFormat("");
    ui->stackedWidget->setCurrentIndex(0);
}

void MainWindow::click_btn_opendirbutton()
{
    btn_opendir->is_release = false;
    if(bFlag_type == 1)
        str_Target = ui->lineEdit_target->text();
    else if(bFlag_type == 2)
        str_Target = ui->lineEdit_target_2->text();
    QFileInfo fi=QFileInfo(str_Target+"/tmp");
    QString filePath;
    filePath=fi.absolutePath();
    QDesktopServices::openUrl(QUrl::fromLocalFile(filePath));
}

void MainWindow::button_desktop_Judge(int id)
{
   switch(id)
   {
       case 0:
       {
           control_xml_1->r_isDesktop->setChecked(true);
           control_xml_1->r_isNoDesktop->setChecked(false);
           break;
       }
       case 1:
       {
           control_xml_1->r_isDesktop->setChecked(false);
           control_xml_1->r_isNoDesktop->setChecked(true);
           break;
       }
        default:
            break;
   }
}

void MainWindow::button_desktop_Judge2(int id)
{
   switch(id)
   {
       case 0:
       {
           control_xml_2->r_isDesktop->setChecked(true);
           control_xml_2->r_isNoDesktop->setChecked(false);
           break;
       }
       case 1:
       {
           control_xml_2->r_isDesktop->setChecked(false);
           control_xml_2->r_isNoDesktop->setChecked(true);
           break;
       }
        default:
            break;
   }
}

void MainWindow::button_patch_Judge(int id)
{
    switch(id)
    {
        case 0:
        {
            control_xml_1->r_isPatch->setChecked(true);
            control_xml_1->r_isNoPatch->setChecked(false);
            break;
        }
        case 1:
        {
            control_xml_1->r_isPatch->setChecked(false);
            control_xml_1->r_isNoPatch->setChecked(true);
            break;
        }
         default:
             break;
    }
}

void MainWindow::button_patch_Judge2(int id)
{
    switch(id)
    {
        case 0:
        {
            control_xml_2->r_isPatch->setChecked(true);
            control_xml_2->r_isNoPatch->setChecked(false);
            break;
        }
        case 1:
        {
            control_xml_2->r_isPatch->setChecked(false);
            control_xml_2->r_isNoPatch->setChecked(true);
            break;
        }
         default:
             break;
    }
}

void MainWindow::button_essential_Judge(int id)
{
    switch(id)
    {
        case 0:
        {
           control_xml_1->r_isEssential->setChecked(true);
            control_xml_1->r_isNoEssential->setChecked(false);
            break;
        }
        case 1:
        {
            control_xml_1->r_isEssential->setChecked(false);
            control_xml_1->r_isNoEssential->setChecked(true);
            break;
        }
         default:
             break;
    }
}

void MainWindow::button_essential_Judge2(int id)
{
    switch(id)
    {
        case 0:
        {
           control_xml_2->r_isEssential->setChecked(true);
            control_xml_2->r_isNoEssential->setChecked(false);
            break;
        }
        case 1:
        {
            control_xml_2->r_isEssential->setChecked(false);
            control_xml_2->r_isNoEssential->setChecked(true);
            break;
        }
         default:
             break;
    }
}

//解包按钮，槽
void MainWindow::slot_Msg_extract_end()
{
    thread_extract->wait();
    delete thread_extract;
    thread_extract->bflag = false;

    QStringList strList;
    strList = soft_name.split(".");
    int nCount = strList.size();
    QString sname;
    if(!strcmp(strList.at(nCount  -1).toLocal8Bit().data(), "deb"))
    {
        strList = soft_name.split(".deb");
        sname = soft_name;
        soft_name = strList.at(0).toLocal8Bit().data();
        cache_dir = debfile_path + soft_name +"_cache";

    }
    else if(!strcmp(strList.at(nCount  -1).toLocal8Bit().data(), "rpm"))
    {
        strList = soft_name.split(".rpm");
        sname = soft_name;
        soft_name = strList.at(0).toLocal8Bit().data();
        cache_dir = debfile_path + soft_name +"_cache";
    }
//  解压，并提取软件包信息，生成详情页，成功返回0，失败返回-1
//    readConf(deb_path, sname);
//  生成安装脚本文件，成功返回0，失败返回-1
//    cpkscriptgeneration();

//    QPixmap p_title2;
//    p_title2.load("/usr/share/cpktransform/images/title_2.png");
//    QPalette palette_title2;
//    palette_title2.setBrush(t->backgroundRole(),QBrush(p_title2));
//    t->setPalette(palette_title2);
//    t->setFixedWidth(p_title2.width());
//    t->setFixedHeight(p_title2.height());

//    ui->progressBar_2->setValue(0);
//    ui->progressBar_2->setFormat("");
//    ui->stackedWidget->setCurrentIndex(2);
    timer->stop();
    btn->is_release = false;
    btn->setEnabled(false);
    tlb->setEnabled(true);

    if( ( readConf(deb_path, sname) == 0 ) && ( cpkscriptgeneration() == 0 ) )
    {
        //更新UI
        QPixmap p_title2;
        p_title2.load("/usr/share/cpktransform/images/title_2.png");
        QPalette palette_title2;
        palette_title2.setBrush(t->backgroundRole(),QBrush(p_title2));
        t->setPalette(palette_title2);
        t->setFixedWidth(p_title2.width());
        t->setFixedHeight(p_title2.height());
        ui->progressBar_2->setValue(0);
        ui->progressBar_2->setFormat("");

        //读取截图数据
        screenshotmodel_loadData();
        //读取icon
        icon_loadData();
        //读取启动器
        desktop_loadData();

        //菜单关联
        static int i = 0;
        if( i++ );
        else{
//            connect(control_xml_2->tv_screenshot->horizontalHeader(),SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(slot_screenshot_menu_show(QPoint)));
            connect(control_xml_2->tv_screenshot,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(slot_screenshot_menu_show(QPoint)));
            connect(control_xml_2->screendshot_menu_edit_action,SIGNAL(triggered(bool)),this,SLOT(slot_screenshot_menu_edit()));
            connect(control_xml_2->screendshot_menu_del_action,SIGNAL(triggered(bool)),this,SLOT(slot_screenshot_menu_del()));

//            connect(control_xml_2->tv_screenshot,SIGNAL(clicked(QModelIndex)),this,SLOT(slot_screenshot_clicked(QModelIndex)));
            //提示
            connect(control_xml_2->tv_screenshot,SIGNAL(entered(QModelIndex)),this,SLOT(slot_screenshot_menu_row_detail(QModelIndex)));
        }

        //跳转界面
        ui->stackedWidget->setCurrentIndex(2);
    }

}
//打包完成槽
void MainWindow::slot_Msg_pack_end( QString errorInfoDes )
{
    if( errorInfoDes == NULL )
    {
        QPixmap pPixTip;
        pPixTip.load("/usr/share/cpktransform/images/tips_success.png");
        pix_tips->setPixmap(pPixTip);
    }
    else
    {
        QPixmap pPixTip;
        pPixTip.load("/usr/share/cpktransform/images/tips_failure.png");
        pix_tips->setPixmap(pPixTip);
    }


    if(bFlag_type == 1)
    {
        timer3->stop();
        thread_package2->wait();
        delete thread_package2;
        thread_package2->bflag_c = false;
        //mencius
        QPixmap p_title1;
        p_title1.load("/usr/share/cpktransform/images/title_3.png");
        QPalette   palette_title1;
        palette_title1.setBrush(t->backgroundRole(),QBrush(p_title1));
        t->setPalette(palette_title1);
        t->setFixedWidth(p_title1.width());
        t->setFixedHeight(p_title1.height());

        //t->setStyleSheet("background-color:rgb(255,255,255)");
        ui->stackedWidget->setCurrentIndex(3);
        if( errorInfoDes == NULL )
        {
            tips->setText("CPK打包成功！");
            btn_opendir->setVisible(true);
            textEdit_errorInfoDes->setVisible(false);
            occupying_page_3->setFixedHeight(200);
        }
        else
        {
            tips->setText("CPK打包失败！");
            btn_opendir->setVisible(false);
            textEdit_errorInfoDes->setVisible(true);
            textEdit_errorInfoDes->setText(errorInfoDes);
            occupying_page_3->setFixedHeight(100);
        }

        delete_data();//删除之前所填数据
        ui->scrollArea_2->verticalScrollBar()->setValue(0);
    }
    else if(bFlag_type == 2)
    {
        timer2->stop();
        thread_package->wait();
        delete thread_package;
        thread_package->bflag_c = false;
        //mencius
        QPixmap p_title1;
        p_title1.load("/usr/share/cpktransform/images/title_3.png");
        QPalette   palette_title1;
        palette_title1.setBrush(t->backgroundRole(),QBrush(p_title1));
        t->setPalette(palette_title1);
        t->setFixedWidth(p_title1.width());
        t->setFixedHeight(p_title1.height());

        ui->stackedWidget->setCurrentIndex(3);
        if( errorInfoDes == NULL )
        {
            tips->setText("CPK转包成功！");
            btn_opendir->setVisible(true);
            textEdit_errorInfoDes->setVisible(false);
            occupying_page_3->setFixedHeight(200);
        }
        else
        {
            tips->setText("CPK转包失败！");
            btn_opendir->setVisible(false);
            textEdit_errorInfoDes->setVisible(true);
            textEdit_errorInfoDes->setText(errorInfoDes);
            occupying_page_3->setFixedHeight(100);
        }
        delete_data();
#if 0
        //删除中间文件及文件夹
        QString tmp = QString("rm -rf %1").arg(cache_dir);
        //system(tmp.toLocal8Bit().data());
        inputShell(tmp.toLocal8Bit().data());
#endif
    }
    //todo
    btn_trans->is_release = false;
    btn_opendir->is_release = false;
    ui->scrollArea->verticalScrollBar()->setValue(0);
}

void MainWindow::timeUpDate()
{
    if(count < 100)
        ui->progressBar->setValue(++count);
    else
        count = 0;
}

void MainWindow::timeUpDate2()
{
    if(count2 < 100)
        ui->progressBar_2->setValue(++count2);
    else
        count2 = 0;
}

void MainWindow::timeUpDate3()
{
    if(count3 < 100)
        ui->progressBar_3->setValue(++count3);
    else
        count3 = 0;
}

void MainWindow::delete_data()
{
    if(bFlag_type == 1 && control_xml_1)
    {
        ui->progressBar_3->setFormat("");
        ui->progressBar_3->setValue(0);
        ui->toolButton_2->setStyleSheet("QToolButton {\
                                         color:rgb(105,105,105);\
                                         background-color:rgb(245,245,245);\
                                          border: 0px solid #8f8f91;\
                                          border-radius: 0px;\
                                      }");
        ui->toolButton_2->setFixedSize(156,40);
        ui->toolButton_3->setStyleSheet(strQToolButton2);
        ui->toolButton_4->setStyleSheet(strQToolButton2);
        ui->toolButton_9->setStyleSheet(strQToolButton2);
        ui->stackedWidget_2->setCurrentIndex(1);
        count3 = 0;

        //清空原始数据内容
        control_xml_1->delete_data();
        l_hp->clear();

        script_line2->clear();
        script_edit2->clear();
        script_edit2->setText("#! /usr/bin/bash\n\
\n\
#在Deb解包之前，将会运行该脚本\n\
pre_install()\n\
{\n\
  :\n\
} \n\
#负责完成安装包时的配置\n\
post_install()\n\
{\n\
  :\n\
} \n\
#负责停止与软件包相关联的daemon服务\n\
pre_remove()\n\
{\n\
  :\n\
} \n\
#负责修改软件包连接或文件关联\n\
post_remove()\n\
{\n\
  :\n\
} \n\
pre_upgrade()\n\
{\n\
  :\n\
} \n\
post_upgrade()\n\
{\n\
  :\n\
} \n\
pre_downgrade()\n\
{\n\
   :\n\
} \n\
post_upgrade()\n\
{\n\
  :\n\
} \n\
      ");

        ui->lineEdit_name->clear();
        ui->lineEdit_genericname->clear();
        ui->lineEdit_comment->setText("");
        ui->lineEdit_type->setText("Application");
        ui->comboBox_type->setCurrentIndex(0);
        ui->lineEdit_icon->clear();
        ui->lineEdit_version->clear();
        ui->lineEdit_exec->clear();
        ui->comboBox_terminal->setCurrentIndex(0);
        ui->comboBox_hidden->setCurrentIndex(0);
        ui->lineEdit_hidden->setText("true");
        ui->lineEdit_terminal->setText("true");
//        ui->lineEdit_category->setText("AudioVideo");
        ui->lineEdit_category->setText("");
//        ui->comboBox_category->setCurrentIndex(0);

        ui->label_tip_xml->clear();
        ui->label_tip_desktop->clear();
        ui->label_tip_install->clear();
        btn_package->is_release = false;
    }
    else if(bFlag_type == 2 && control_xml_2)
    {
        //清空原始数据内容
        control_xml_2->delete_data();
        version.clear();
        m_bLeftButtonPress = false;
        script_edit->clear();
        script_line->clear();
        btn_transfer->is_release = false;

//        //    转包详情页左侧详细信息清空
//        if(ui->label_packname)
//        {
//            ui->label_packname->setText(" Unknown");
//        }
//        if(ui->label_version)
//        {
//            ui->label_version->setText(" Unknown");
//        }
//        if(ui->label_arch)
//        {
//            ui->label_arch->setText(" Unknown");
//        }
//        if(ui->label_maintainer)
//        {
//            ui->label_maintainer->setText(" Unknown");
//        }
//        if(ui->label_installedSize)
//        {
//            ui->label_installedSize->setText(" Unknown");
//        }
//        if(ui->label_section)
//        {
//            ui->label_section->setText(" Unknown");
//        }
//        if(ui->label_hp)
//        {
//            ui->label_hp->setText(" Unknown");
//        }
    }
}

//从install/desktop文件中读取数据到界面(打包->“选择源文件夹”页 page_10->详细信息页 page_4)中
int MainWindow::read_fileinfo_to_ui()
{
    File f;
    QString str_cpk_path = str_Source +"/CPK";
    QFileInfo file(str_Source+"/CPK");

    if(!file.exists())
    {
        //not exist CPK
        //创建文件夹
        if(mkdir(str_cpk_path.toLocal8Bit().data(), 00700) < 0)
        {
            emit signal_Msg_error("该路径权限较高");
            return -1;
        }
    }
    file.setFile(str_cpk_path+"/control.xml");
    if(file.exists())
    {
        //exit control.xml,write it to ui
        write_xml_to_ui();
    }
    else
    {
        //从lineEdit_source中分解出软件的名称、版本号、架构，然后填入基本信息的相关位置
        QStringList strList;
        strList = str_Source.split("/");
        int nCount = strList.size();
        QString strInfo = strList.at(nCount - 1);
        strList = strInfo.split("_");
        nCount = strList.size();
        if(nCount >= 3)
        {
            QString strName = strList.at(0);
            QString strVersion = strList.at(1);
            QString strArch = strList.at(2);
            if(control_xml_1)
            {
                control_xml_1->sname_en->setText(strName);
                strList = strVersion.split(".");
                nCount = strList.size();
                if(nCount >= 3)
                {
                    control_xml_1->l_1->setText(strVersion.split(".").at(0));
                    control_xml_1->l_2->setText(strVersion.split(".").at(1));
                    control_xml_1->l_3->setText(strVersion.split(".").at(2));
                }
                control_xml_1->larch->setText(strArch);
                control_xml_1->lExec->setText("/usr/bin/");
            }
        }
    }
    //write .install to ui
    QString strCPK = str_Source+"/CPK/";
    QFileInfoList list = QDir(strCPK).entryInfoList();
    for(int i = 0; i < list.size(); ++i){
        QFileInfo fileInfo = list.at(i);
        QString name = fileInfo.fileName();
        QStringList strList = name.split(".");
        if(strList.size() == 2 && !strcmp(strList.at(1).toLocal8Bit().data(),"install"))
        {
            QString path = fileInfo.filePath();
            script_line2->setText(name);
            QTextCodec * code = QTextCodec::codecForName("utf8");
            QFile file(path);
            if ( !file.open(QIODevice::ReadOnly | QIODevice::Text) )
            {
                emit signal_Msg_error("file open error!");
                return -1;
            }

            QTextStream stream(&file);
            stream.setCodec(code);//对输出流的设置
            while (stream.atEnd() == 0) {
                script_edit2->setText(stream.readAll());
            }
        }
    }
    //write .desktop to ui
    for(int i = 0; i < list.size(); ++i){
        QFileInfo fileInfo = list.at(i);
        QString name = fileInfo.fileName();
        QStringList strList = name.split(".");
        if(strList.size() == 2 && !strcmp(strList.at(1).toLocal8Bit().data(),"desktop"))
        {
            QString path = fileInfo.filePath();
            QString Name = f.conf_get_uri(path.toLocal8Bit().data(), "Name");
            QString GenericName = f.conf_get_uri(path.toLocal8Bit().data(), "GenericName");
            QString Comment = f.conf_get_uri(path.toLocal8Bit().data(), "Comment");
            QString Type = f.conf_get_uri(path.toLocal8Bit().data(), "Type");
            QString Version = f.conf_get_uri(path.toLocal8Bit().data(), "Version");
            QString Exec = f.conf_get_uri(path.toLocal8Bit().data(), "Exec");
            QString Terminal = f.conf_get_uri(path.toLocal8Bit().data(), "Terminal");
            QString Hidden = f.conf_get_uri(path.toLocal8Bit().data(), "Hidden");
            printf("Hidden:%s",Hidden.toUtf8().data());
            QString Categories = f.conf_get_uri(path.toLocal8Bit().data(), "Categories");
            QString Icon =  f.conf_get_uri(path.toLocal8Bit().data(), "Icon");
            if(!Name.isNull() && !Name.isEmpty())
                ui->lineEdit_name->setText(Name);
            if(!GenericName.isNull() && !GenericName.isEmpty())
                ui->lineEdit_genericname->setText(GenericName);
            if(!Comment.isNull() && !Comment.isEmpty())
                ui->lineEdit_comment->setText(Comment);
            if(!Type.isNull() && !Type.isEmpty())
                ui->lineEdit_type->setText(Type);
            if(!Icon.isNull() && !Icon.isEmpty())
                ui->lineEdit_icon->setText(Icon);
            if(!Version.isNull() && !Version.isEmpty())
                ui->lineEdit_version->setText(Version);
            if(!Exec.isNull() && !Exec.isEmpty())
                ui->lineEdit_exec->setText(Exec);
            if(!Terminal.isNull() && !Terminal.isEmpty())
                ui->lineEdit_terminal->setText(Terminal);
            if(!Hidden.isNull() && !Hidden.isEmpty()){
                printf("hidden:%s",Hidden.toUtf8().data());
                ui->lineEdit_hidden->setText(Hidden);

//                if( Hidden == "true" ){
//                    ui-> comboBox_hidden->setCurrentIndex(0);
//                }else{
//                    ui->comboBox_hidden->setCurrentIndex(1);
//                }

            }
            if(!Categories.isNull() && !Categories.isEmpty())
                ui->lineEdit_category->setText(Categories);
        }
    }
    return 0;
}
//解析xml创建UI
int MainWindow::write_xml_to_ui()
{
    QFile file(str_Source+"/CPK/control.xml");
    if(!file.open(QFile::ReadOnly | QFile::Text))
    {
        qDebug()<< "open file control.xml failed,error:"<<file.errorString() ;

        QString str_error = "open file control.xml failed,error:";
        str_error.append(file.errorString());
        emit signal_Msg_error(str_error);
        return -1;
    }
    /*解析Dom节点*/
    QDomDocument document;
    QString strError;
    int errLin = 0, errCol = 0;
    if( !document.setContent(&file, false, &strError, &errLin, &errCol) ) {
        qDebug()<<"parse file failed at line"<<errLin<<",column"<<errCol<<","<<strError;
        //            return;
        QString str_error = "parse file failed at line";
        str_error.append(errLin);
        str_error.append(",column");
        str_error.append(errCol);
        str_error.append(",");
        str_error.append(strError);
        emit signal_Msg_error(str_error);
        return -1;
    }

    if( document.isNull() ) {
        qDebug()<<"document is null !";
        //            return;
        emit signal_Msg_error("document is null !");
        return -1;
    }
    QDomElement root = document.documentElement();
    qDebug()<<root.tagName();// output "CpkInfo"

    QDomElement catalogs = root.firstChildElement();
    if( catalogs.isNull() )
        return -1;
    else
        qDebug()<<catalogs.tagName(); //output "Software"

    if(control_xml_1)
    {
        control_xml_1->sname_en->setText(catalogs.lastChildElement("genericname").firstChildElement("keyword").text());
        control_xml_1->sname->setText(catalogs.lastChildElement("genericname").lastChildElement("keyword").text());
        if(!strcmp(catalogs.lastChildElement("category").firstChild().toText().data().toStdString().data(),"Application"))
            control_xml_1->scategory->setCurrentIndex(1);
        if(!strcmp(catalogs.lastChildElement("category").firstChild().toText().data().toStdString().data(),"Office"))
            control_xml_1->scategory->setCurrentIndex(0);
        if(!strcmp(catalogs.lastChildElement("category").firstChild().toText().data().toStdString().data(),"Network"))
            control_xml_1->scategory->setCurrentIndex(2);
        if(!strcmp(catalogs.lastChildElement("category").firstChild().toText().data().toStdString().data(),"IM"))
            control_xml_1->scategory->setCurrentIndex(3);
        if(!strcmp(catalogs.lastChildElement("category").firstChild().toText().data().toStdString().data(),"Graphics"))
            control_xml_1->scategory->setCurrentIndex(4);
        if(!strcmp(catalogs.lastChildElement("category").firstChild().toText().data().toStdString().data(),"Mutimedia"))
            control_xml_1->scategory->setCurrentIndex(5);
        if(!strcmp(catalogs.lastChildElement("category").firstChild().toText().data().toStdString().data(),"Security"))
            control_xml_1->scategory->setCurrentIndex(6);
        if(!strcmp(catalogs.lastChildElement("category").firstChild().toText().data().toStdString().data(),"System"))
            control_xml_1->scategory->setCurrentIndex(7);
        if(!strcmp(catalogs.lastChildElement("category").firstChild().toText().data().toStdString().data(),"Development"))
            control_xml_1->scategory->setCurrentIndex(8);
        if(!strcmp(catalogs.lastChildElement("category").firstChild().toText().data().toStdString().data(),"Other"))
            control_xml_1->scategory->setCurrentIndex(9);
        QStringList strList = catalogs.lastChildElement("version").firstChild().toText().data().split(".");
        int nCount = strList.size();
        if(nCount >= 3)
        {
            control_xml_1->l_1->setText(strList.at(0));
            control_xml_1->l_2->setText(strList.at(1));
            control_xml_1->l_3->setText(strList.at(2));
        }
        control_xml_1->larch->setText(catalogs.lastChildElement("architecture").firstChild().toText().data());
        //qDebug()<< catalogs.lastChildElement("pkgs").lastChildElement("depends").firstChild().toText().data();
        if(!strcmp(catalogs.lastChildElement("pkgs").lastChildElement("depends").firstChild().toText().data().toStdString().data(),"ccf1 (>= 1.0.0)"))
            control_xml_1->sdenpendence->setCurrentIndex(0);
        else
            control_xml_1->sdenpendence->setCurrentIndex(1);
        control_xml_1->lExec->setText(catalogs.lastChildElement("exec").firstChild().toText().data());
        if(!strcmp(catalogs.lastChildElement("classification").firstChild().toText().data().toStdString().data(),"L0"))
            control_xml_1->sdense->setCurrentIndex(0);
        else if(!strcmp(catalogs.lastChildElement("classification").firstChild().toText().data().toStdString().data(),"L1"))
            control_xml_1->sdense->setCurrentIndex(1);
        else if(!strcmp(catalogs.lastChildElement("classification").firstChild().toText().data().toStdString().data(),"L2"))
            control_xml_1->sdense->setCurrentIndex(2);
        else if(!strcmp(catalogs.lastChildElement("classification").firstChild().toText().data().toStdString().data(),"L3"))
            control_xml_1->sdense->setCurrentIndex(3);
        else if(!strcmp(catalogs.lastChildElement("classification").firstChild().toText().data().toStdString().data(),"L4"))
            control_xml_1->sdense->setCurrentIndex(4);

        control_xml_1->lsdesc_en->setText(catalogs.lastChildElement("summary").firstChildElement("keyword").text());
        control_xml_1->lsdesc->setText(catalogs.lastChildElement("summary").lastChildElement("keyword").text());
        control_xml_1->tldesc_en->setText(catalogs.lastChildElement("description").firstChildElement("keyword").text());
        control_xml_1->tldesc->setText(catalogs.lastChildElement("description").lastChildElement("keyword").text());

        QStringList str_Permission = catalogs.lastChildElement("permission").firstChild().toText().data().split(";");
        nCount = str_Permission.size() - 1;
        for(int i =0; i <nCount; i++)
        {
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.USE_ROOT"))
                control_xml_1->root_user->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.USE_SUDO"))
                control_xml_1->sudo_user->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.USE_IPC"))
                control_xml_1->ipc_user->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.ACCESS_NETWORK_STATE"))
                control_xml_1->s_n_access->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.ACCESS_NETWORK"))
                control_xml_1->network_access->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.ACCESS_XORG"))
                control_xml_1->xorg_access->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.USER_MANAGER"))
                control_xml_1->manager_user->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.USER_GROUP_MANAGER"))
                control_xml_1->m_g_user->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.SYSTEM_VARIABLE"))
                control_xml_1->variable_system->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.DEVICE_MANAGER"))
                control_xml_1->manager_device->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.OPEN_INPUT_METHOD"))
                control_xml_1->m_i_open->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.APP_MANAGER"))
                control_xml_1->manager_app->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.SYSTEM_SETTING"))
                control_xml_1->setting_system->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.CHANGE_CONFIGURATION"))
                control_xml_1->conf_change->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.CLEAR_APP_CACHE"))
                control_xml_1->c_a_c->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.CLEAR_APP_USER_DATA"))
                control_xml_1->d_u_a_c->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.ACCESS_UNDERLY"))
                control_xml_1->underly_access->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.DELETE_CACHE_FILES"))
                control_xml_1->f_c_d->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.DIAGNOSTIC"))
                control_xml_1->diagnostic->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.DUMP"))
                control_xml_1->dump->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.CHANGE_DEFAULT_APP"))
                control_xml_1->a_d_c->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.CHANGE_START_MENU"))
                control_xml_1->m_s_c->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.CHANGE_TASK_BAR"))
                control_xml_1->b_t_c->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.GET_TASKS"))
                control_xml_1->tasks_get->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.GET_TASKS"))
                control_xml_1->tasks_get->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.GLOBAL_SEARCH"))
                control_xml_1->search_global->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.KILL_BACKGROUND_PROCESSES"))
                control_xml_1->p_b_k->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.MASTER_CLEAR"))
                control_xml_1->clear_master->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.MODIFY_AUDIO_SETTINGS"))
                control_xml_1->s_a_m->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.MOUNT_FORMAT_FILESYSTEMS"))
                control_xml_1->f_f_m->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.MOUNT_UNMOUNT_FILESYSTEMS"))
                control_xml_1->f_u_m->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.READ_FRAME_BUFFER"))
                control_xml_1->b_f_r->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.READ_INPUT_STATE"))
                control_xml_1->s_i_r->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.READ_LOGS"))
                control_xml_1->logs_read->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.REBOOT"))
                control_xml_1->reboot->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.RECEIVE_BOOT_COMPLETED"))
                control_xml_1->c_b_r->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.SET_PROCESS_LIMIT"))
                control_xml_1->l_p_s->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.SET_TIME"))
                control_xml_1->time_set->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.SET_TIME_ZONE"))
                control_xml_1->z_t_s->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.USE_CREDENTIALS"))
                control_xml_1->credentials_use->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"com.ccf.browser.permission.CHANGE_BROWSER_HOME"))
                control_xml_1->h_b_c->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"com.ccf.browser.permission.READ_HISTORY_BOOKMARKS"))
                control_xml_1->b_h_r->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"com.ccf.browser.permission.WRITE_HISTORY_BOOKMARKS"))
                control_xml_1->b_h_w->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.ACCESS_WIFI_STATE"))
                control_xml_1->s_w_a->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.CHANGE_WIFI_STATE"))
                control_xml_1->s_w_c->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.USE_BLUETOOTH"))
                control_xml_1->bluetooth->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.BLUETOOTH_MANAGER"))
                control_xml_1->manager_bluetooth->setChecked(true);
            if(!strcmp(str_Permission.at(i).toStdString().data(),"ccf.permission.DEVICE_POWER"))
                control_xml_1->power_device->setChecked(true);
        }

        if(!strcmp(catalogs.lastChildElement("vendor").attributeNode("type").value().toStdString().data(),"company"))
        {
            control_xml_1->r_enterprise->setChecked(true);
            control_xml_1->r_individual->setChecked(false);
        }
        else
        {
            control_xml_1->r_enterprise->setChecked(false);
            control_xml_1->r_individual->setChecked(true);
        }
        control_xml_1->l_name->setText(catalogs.lastChildElement("vendor").lastChildElement("name").firstChild().toText().data());
        control_xml_1->l_tel->setText(catalogs.lastChildElement("vendor").lastChildElement("telephone").firstChild().toText().data());
        control_xml_1->l_email->setText(catalogs.lastChildElement("vendor").lastChildElement("email").firstChild().toText().data());
        control_xml_1->l_pg->setText(catalogs.lastChildElement("vendor").lastChildElement("url").firstChild().toText().data());
        control_xml_1->l_desc_en->setText(catalogs.lastChildElement("vendor").lastChildElement("description").firstChildElement("keyword").text());
        control_xml_1->l_desc->setText(catalogs.lastChildElement("vendor").lastChildElement("description").lastChildElement("keyword").text());

        if(!strcmp(catalogs.lastChildElement("genericname").attributeNode("type").value().toStdString().data(),"desktop"))
        {
            control_xml_1->r_isDesktop->setChecked(true);
            control_xml_1->r_isNoDesktop->setChecked(false);
        }
        else
        {
            control_xml_1->r_isDesktop->setChecked(false);
            control_xml_1->r_isNoDesktop->setChecked(true);
        }
        if(!strcmp(catalogs.lastChildElement("is_patch").firstChild().toText().data().toStdString().data(), "0"))
            control_xml_1->r_isPatch->setChecked(false);
        else
            control_xml_1->r_isPatch->setChecked(true);
        if(!strcmp(catalogs.lastChildElement("essential").firstChild().toText().data().toStdString().data(), "0"))
            control_xml_1->r_isEssential->setChecked(false);
        else
            control_xml_1->r_isEssential->setChecked(true);
        control_xml_1->lprotocol->setText(catalogs.lastChildElement("license").firstChild().toText().data());
        l_hp->setText(catalogs.lastChildElement("homepage").firstChild().toText().data());
    }
    file.close();
    return 0;
}

void MainWindow::click_button_Undo_Script()
{
    script_line2->clear();
    script_edit2->clear();
    script_edit2->setText("#! /usr/bin/bash\n\
\n\
#在Deb解包之前，将会运行该脚本\n\
pre_install()\n\
{\n\
  :\n\
} \n\
#负责完成安装包时的配置\n\
post_install()\n\
{\n\
  :\n\
} \n\
#负责停止与软件包相关联的daemon服务\n\
pre_remove()\n\
{\n\
  :\n\
} \n\
#负责修改软件包连接或文件关联\n\
post_remove()\n\
{\n\
  :\n\
} \n\
pre_upgrade()\n\
{\n\
  :\n\
} \n\
post_upgrade()\n\
{\n\
  :\n\
} \n\
pre_downgrade()\n\
{\n\
   :\n\
} \n\
post_upgrade()\n\
{\n\
  :\n\
} \n\
  ");
}

